近公司需要弄webservics,还说不用框架整合(提倡使用hessian,他们既然说与操作系统有兼容问题,由于人员单薄,不得不屈服,哎),我想了老半天没弄明白他说的不用框架整合spring,尝试过直接使用Endpoint.publish("http://127.0.0.1:6789/hello", new HelloService());【第一个参数是暴露借口的url,参数+?wsdl就可以获取wsdl文档;第二个参数是要对外发布的服务器,不是接口】由于服务器是直接new出来的,不归spring管理,所以在获取系统的中services时候,注入不了,网上各种搜索,也尝试过用Axis2整合spring,但是好像挺麻烦的。

导入CXF与spring整合需要的jar(这事三大框架整合过后的jar):

cxf-2.4.2.jar

geronimo-annotation_1.0_spec-1.1.1.jar

geronimo-jaxws_2.2_spec-1.0.jar

geronimo-jms_1.1_spec-1.1.1.jar

geronimo-servlet_3.0_spec-1.0.jar

geronimo-ws-metadata_2.0_spec-1.1.3.jar

jaxb-api-2.2.1.jar

jaxb-impl-2.2.1.1.jar

neethi-3.0.1.jar

wsdl4j-1.6.2.jar

xmlschema-core-2.0.jar

两种方式发布服务,一种是接口,一种是非接口

接口发布:

 package com.yidu.zh.cxf.service;

 import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;
@WebService
//@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)//JDK1.6以上才支持1.2,否则会报错:org.apache.cxf.binding.soap.SoapFault
 public interface HiService {  public String sayHi(String name);  }

接口实现类:

package com.yidu.zh.cxf.service;

public class HiServiceImpl implements HiService {

    @Override
public String sayHi(String name) {
System.out.println("正在执行方法!");
return "hello"+name;
} }

spring配置:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- 方式二:有接口的方式 -->
<!--
ID:标识唯一
serviceClass:接口类型(发布的服务器类;必须加上@WebService注解)
address:服务请求url(结合web.xml的映射就是:http://localhost:8080/项目名称/cxf/hi?wsdl)
-->
<jaxws:server id="hiService" serviceClass="com.yidu.zh.cxf.service.HiService" address="hi">
<!-- 提供接口的实现类;服务的实现类 -->
<jaxws:serviceBean>
<bean class="com.yidu.zh.cxf.service.HiServiceImpl"></bean>
</jaxws:serviceBean>
<!-- 加入请求的消息拦截器 -->
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<!-- 加入响应的消息拦截器 -->
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server> </beans>

web.xml配置(发布服务的两种在方式在web.xml配置都一样):

 <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>CXF_Web_WebService</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<!-- 配置CXF框架 -->
</welcome-file-list>
<!-- 通过上下文参数指定spring配置文件的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:cxf-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/cxf/*</url-pattern>
</servlet-mapping> </web-app>

无接口方式:

服务类:

 package com.yidu.zh.cxf.service;

 import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding; /**
*
* @author Administrator
*
*/
@WebService
//@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)//修改服务器版本为1.2,JDK1.6以上才支持1.2,否则会报错:org.apache.cxf.binding.soap.SoapFault
public class HelloService {
public String sayHello(String name){
System.out.println("正在执行服务器中的方法");
return "hello " + name;
}
}

spring配置:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- 方式一;没有借口的方式(简单方式) -->
<!--
ID:唯一标识
implementor:借口的实现的;这里没有接口,直接写类(也就是发布的服务器;该类或接口必须使用@WebService注解)
address:访问的资源名称(通过工程的名称加上该属性值获取wsdl文件)
-->
<jaxws:endpoint id="helloService" implementor="com.yidu.zh.cxf.service.HelloService" address="hello">
<!-- 加入请求的消息拦截器 -->
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<!-- 加入响应的消息拦截器 -->
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:endpoint> </beans>

最新文章

  1. 一步步学习javascript基础篇(9):ajax请求的回退
  2. 分布式系统理论进阶 - Paxos
  3. MMORPG大型游戏设计与开发(服务器 AI 逻辑设定和状态结点)
  4. [LintCode] Intersection of Two Arrays 两个数组相交
  5. ASP.NET的一般处理程序对数据的基本操作
  6. hive-通过Java API操作
  7. WPF中映射clr namspace
  8. Contains Duplicate II leetcode
  9. ABP从入门到精通(6):快速重命名解决方案
  10. xlsx批量转为utf8的csv
  11. 用于ViEmu的重置为试用状态的Python脚本
  12. spring-petclinic性能调优实战(转)
  13. java中Map集合的常用方法 (转)
  14. 宿主机系统 Deepin 15.4,解决 Virtualbox 5.1 中 XP虚拟机无法使用 USB设备(如:U盘、罗技优联接收器等)的问题
  15. Oracle Enterprise Linux 6.4 下配置vncserver
  16. npm 淘宝镜像
  17. sql的存储过程实例--循环动态创建表
  18. RTC(x86)
  19. ubuntu16.04 eclipse+pydev 配置
  20. Codeforces 280C Game on tree【概率DP】

热门文章

  1. Swift基础之UIImageView(都是2.2版本)
  2. Java集合之Hashtable
  3. 【Qt编程】基于Qt的词典开发系列&lt;三&gt;--开始菜单的设计
  4. CentOS 6.X启动流程
  5. 【66】Scanner类用法详解
  6. “《编程珠玑》(第2版)第2章”:A题(二分搜索)
  7. Socket层实现系列 — listen()的实现
  8. HBase Bulk Loading
  9. PHP获取指定地区的天气
  10. JDBC 连接Oracle