一:定义接口
@WebService(targetNamespace = "http://www.unionpay.com/client/appprovider", name = "appManageToAppProvider") @XmlSeeAlso({com.cup.tsm.domain.databinding.jaxb.ObjectFactory.class, ObjectFactory.class}) @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) public interface AppManageToAppProvider {
public void GetSay(String Name);
}
二:定义接口的实现
public class AppManageToAppProviderImpl implements AppManageToAppProvider{
public void GetSay(String Name) {
System.out.println("nihao :"+Name);
}
}
三: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:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="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://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
default-autowire="byType" default-lazy-init="true">
<description>使用Apache CXF的Web Service配置文件,以下三个为固定配置文件(不需要创建)
</description>
<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="sump1"
implementor="com.cup.tsm.integration.webservice.appprovider.AppManageToAppProviderImpl"
address="/appManageToAppProvider">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
</jaxws:inInterceptors>
<!--
<jaxws:inInterceptors>
<bean class="com.cup.tsm.integration.webservice.appprovider.RequestInterceptor"/>
</jaxws:inInterceptors>
-->
</jaxws:endpoint>
</beans>
四: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" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- 环境参数配置 -->
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value> /WEB-INF/applicationContext.xml </param-value>
</context-param>
<!-- CXF -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
五:创建服务端
public class AppManageToAppProvider_AppManageToAppProviderPort_Server{
protected AppManageToAppProvider_AppManageToAppProviderPort_Server() throws java.lang.Exception {
System.out.println("Starting Server");
Object implementor = new AppManageToAppProviderImpl();
String address = "http://localhost:7001/test/mtom";
Endpoint.publish(address, implementor);
}
public static void main(String args[]) throws java.lang.Exception {
new AppManageToAppProvider_AppManageToAppProviderPort_Server();
System.out.println("Server ready...");
JaxWsServerFactoryBean factory=new JaxWsServerFactoryBean();
factory.setServiceClass(AppManageToAppProviderImpl.class);
factory.setAddress("http://localhost:7001/test/mtom");
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
// Thread.sleep(5 * 60 * 1000);
// System.out.println("Server exiting");
// System.exit(0); }
六:soapui工具测试
七:控制台运行结果
《3014-03-13》--renjie