加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

CXF WebServices 集成Spring

发布时间:2020-12-17 00:59:31 所属栏目:安全 来源:网络整理
导读: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.springf

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读