CXF的配置和开发流程
第一种方式
配置信息如下
1、 cxf用的jar包/download.html可以下载到。
2、 l
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
f.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
3、配置文件applicationContext-service.xml(注意红部分为配置文件新加配置)
service fault<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:jaxws="/jaxws"
xmlns:jaxrs="/jaxrs"
xsi:schemaLocation="
/schema/beans /schema/beans/spring-beans.xsd
/jaxws /schemas/jaxws.xsd
/jaxws /schemas/jaxws.xsd
/jaxrs /schemas/jaxrs.xsd
/transports/http/configuration
/schemas/configuration/http-conf.xsd
">
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<jaxws:endpoint id="method2"
implementor="com.fxb.webservice.service.impl.HelloServiceImpl"
address="/HelloWorldTwo">
<jaxws:inInterceptors>
<bean class="com.fxb.webservice.interceptor.MyInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="com.fxb.webservice.interceptor.MyInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:endpoint>
配置文件applicationContext-client.xml
注意applicationContext-service.xml配置文件中使用的是<jaxws:endpoint></jaxws:endpoint>标签
4、服务类HelloService.java
@WebService
public interface HelloService {
public TestResponse hello(@WebParam(name="name")String name);
}
实现类HelloServiceImpl.java
TestResponse.java、TestList.java
5、客户端类HelloClient.java
6、MyInterceptor.java
各部分代码如下
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "java.sun/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/l</param-value>
</context-param>
<listener>
<listener-class>
org.t.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
f.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
</web-app>
applicationContext-service.xml<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:jaxws="/jaxws"
xmlns:jaxrs="/jaxrs"
xsi:schemaLocation="
/schema/beans /schema/beans/spring-beans.xsd
/jaxws /schemas/jaxws.xsd
/jaxws /schemas/jaxws.xsd
/jaxrs /schemas/jaxrs.xsd
/transports/http/configuration
/schemas/configuration/http-conf.xsd
">
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" />
<bean id="helloService" class="com.fxb.webservice.service.impl.HelloServiceImpl">
</bean>
<jaxws:endpoint id="method2"
implementor="com.fxb.webservice.service.impl.HelloServiceImpl"
address="/HelloWorldTwo">
<jaxws:inInterceptors>
<bean class="com.fxb.webservice.interceptor.MyInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="com.fxb.webservice.interceptor.MyInterceptor"></bean>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论