apache cxf-2.4.3 +spring-3.0.5釋出SOAP協議WebService服務

suyunlong發表於2017-04-23

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服務釋出成功!




相關文章