您的位置:首页 > 运维架构 > Apache

apache cxf-2.4.3 +spring-3.0.5发布SOAP协议WebService服务

2017-04-23 12:12 351 查看
1.apache cxf-2.4.3导入相关架包:

commons-net-3.3.jar

cxf-2.4.3.jar

geronimo-jaxws_2.2_spec-1.1.jar

geronimo-servlet_3.0_spec-1.0.jar

jaxb-api-2.2.6.jar

jaxb-impl-2.2.6.jar

neethi-3.0.1.jar

stax2-api-3.1.4.jar

woodstox-core-asl-4.4.1.jar

wsdl4j-1.6.3.jar

xmlschema-core-2.1.0.jar

2.ApplySOAPService接口

package demo.spring.service;

import java.util.List;
import javax.jws.WebService;

/**
* SOAP��WebService
* @author suyunlong
*
*/
@WebService
public interface ApplySOAPService {
public String returnSOAPFile(String applySerialNumber,SealFile sealFiles);
public String returnUsedEsealFile(String applySerialNumber,List<SealFile> sealFiles);
}3.ApplySOAPServiceImpl接口实现类
package demo.spring.service;

import java.util.List;
import javax.jws.WebService;

/**
* SOAPЭ��WebService����ʵ����
* @author suyunlong
*
*/
@WebService(targetNamespace="http://demo.spring.service",
endpointInterface="demo.spring.service.ApplySOAPService")
public class ApplySOAPServiceImpl implements ApplySOAPService{
public String returnSOAPFile(String applySerialNumber,SealFile sealFiles) {
return "Hello "+applySerialNumber+","+sealFiles.getFileName();
}
public String returnUsedEsealFile(String applySerialNumber,List<SealFile> sealFiles){
return "Hello "+applySerialNumber+","+sealFiles.get(0).getFileName()+","+
sealFiles.size();
}
}4.applicationContext.xml配置文件
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.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 http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"
default-autowire="byName" default-lazy-init="false">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<jaxws:endpoint id="applySOAPService" 
    implementor="demo.spring.service.ApplySOAPServiceImpl" address="/ApplySOAPService">
    </jaxws:endpoint>
</beans>5.web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>6.启动Tomcat服务,浏览器中访问http://localhost:8095/mybatis/services/ApplySOAPService?wsdl,显示WSDL文档,即表示WebService服务发布成功!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web service soap cxf