微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CXF WebServices 集成Spring

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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <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" /> <!--JAX-WS ednpoint Spring方式配置CXF服务端 --> <jaxws:endpoint id="welcome" implementor="com.ws.WelcomeImpl" address="/welcome"/> <!--JAX-WS server Spring方式配置CXF服务端 --> <jaxws:server id="welcome2" serviceClass="com.ws.WelcomeImpl" address="/welcome2"/> <!--JAX-WS client Spring方式配置CXF客户端 --> <jaxws:client id="welcomeService" serviceClass="com.ws.Welcome" address="http://localhost:8080/Demo/webservice/welcome2"/> <!-- JAX-WS proxy factory方式配置CXF客户端--> <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyfactorybean"> <property name="serviceClass" value="com.ws.Welcome" /> <property name="address" value="http://127.0.0.1:8080/Demo/webservice/welcome?wsdl" /> </bean> <bean id="welcomeService2" class="com.ws.Welcome" factory-bean="clientFactory" factory-method="create"/> </beans>

web.xml配置

加入Spring和CXF的启动配置
<context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/classes/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <display-name>CXFServlet</display-name> <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>/webservice/*</url-pattern> </servlet-mapping>
发布到Tomcat,直接访问:http://localhost:8080/Demo/webservice  可以看到CXF发布的所有SOAP services和RESTful services
http://localhost:8080/Demo/webservice/welcome/getWelcome?name=jock  在服务后面添加方法名,问号后面添加参数,返回服务调用结果。
详细配置参数见:http://cxf.apache.org/docs/jax-ws-configuration.htmlJAXWS frontend server and client spring configuration: http://cxf.apache.org/docs/simple-frontend-configuration.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐