在spring中集成webservice 框架 CXF
2012-11-21 15:25
573 查看
首先 构建环境
1.在eclipse下新建个web项目(我比较喜欢用eclipse),接着添加CXF必须依赖的jar包
commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
2.添加spring jar包
aopalliance-1.0.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar
3.构建webservice 本例子是基于jdk1.5 或者更高的版本 通过注解来构建webservice
webservice的接口
package demo.spring;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String
sayHi(String text);
}
webservice 的接口实现
package demo.spring;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public
String sayHi(String text) {
return
"Hello " + text;
}
}
4 。 spring bean的配置文件
bean.xml
<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" />
<bean id="hello" class="demo.spring.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />
<!-- 另一种写法 是
<jaxws:endpoint id="helloWorld" implementor="demo.spring.HelloWorldImpl" address="/HelloWorld"
/>
在这里我建议不要用这种方法 ,如果实现类有的属性要通过spring依赖注入的话,这种方法只是简单的new个实现类,他的属性没有通过spring依赖注入给注入值
所有综合考虑 建议使用上面的写法!
-->
</beans>
5. web.xml加载bean.xml文件
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-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>/services/*</url-pattern>
</servlet-mapping>
</web-app>
6.创建客户端配置文件
client-bean.xml
<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-2.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
<bean
id="client" class="demo.spring.HelloWorld"
factory-bean="clientFactory"
factory-method="create"/>
<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property
name="serviceClass" value="demo.spring.HelloWorld"/>
<property
name="address" value="http://localhost:8080/HelloWorld"/>
</bean>
</beans>
7.客户端访问
ApplicationContext context = ...; // your Spring ApplicationContext
HellWorld client = (HelloWorld) context.getBean("client");
OK 。。。其实就是这样的哦。。。。
1.在eclipse下新建个web项目(我比较喜欢用eclipse),接着添加CXF必须依赖的jar包
commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
2.添加spring jar包
aopalliance-1.0.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar
3.构建webservice 本例子是基于jdk1.5 或者更高的版本 通过注解来构建webservice
webservice的接口
package demo.spring;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String
sayHi(String text);
}
webservice 的接口实现
package demo.spring;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public
String sayHi(String text) {
return
"Hello " + text;
}
}
4 。 spring bean的配置文件
bean.xml
<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" />
<bean id="hello" class="demo.spring.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />
<!-- 另一种写法 是
<jaxws:endpoint id="helloWorld" implementor="demo.spring.HelloWorldImpl" address="/HelloWorld"
/>
在这里我建议不要用这种方法 ,如果实现类有的属性要通过spring依赖注入的话,这种方法只是简单的new个实现类,他的属性没有通过spring依赖注入给注入值
所有综合考虑 建议使用上面的写法!
-->
</beans>
5. web.xml加载bean.xml文件
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-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>/services/*</url-pattern>
</servlet-mapping>
</web-app>
6.创建客户端配置文件
client-bean.xml
<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-2.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
<bean
id="client" class="demo.spring.HelloWorld"
factory-bean="clientFactory"
factory-method="create"/>
<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property
name="serviceClass" value="demo.spring.HelloWorld"/>
<property
name="address" value="http://localhost:8080/HelloWorld"/>
</bean>
</beans>
7.客户端访问
ApplicationContext context = ...; // your Spring ApplicationContext
HellWorld client = (HelloWorld) context.getBean("client");
OK 。。。其实就是这样的哦。。。。
相关文章推荐
- Spring 集成CXF框架发布Webservice服务 和 使用jdk生成Webservice clinet
- spring集成webservice框架cxf,访问报错service not found
- Java CXF WebService框架 集成Spring3 自定义拦截器进行头验证
- 基于Maven环境进行Spring集成CXF WebService框架
- 在spring中集成webservice 框架 CXF
- WebService的CXF框架整合Spring
- WebService-06-CXF与Spring集成
- 一个CXF集成SPRING的WEBSERVICE完整实例
- 框架 day64 WebService(注解),CXF框架(jax-ws,Jax-rs,与spring整合)
- 最简单的cxf restful webservice Demo(包括与spring集成)
- WebService之Spring中集成CXF
- Spring 部署CXF 框架--WebService
- Spring集成CXF搭建WebService服务端与客户端
- CXF 实现webservice例子 集成spring
- WebService(注解),CXF框架(jax-ws,Jax-rs,与spring整合)
- webService快速入门入门系列《6》----cfx框架集成spring
- 脱离spring集成cxf(基于nutz框架)
- WebService技术中CXF框架与Spring整合和常见bug
- 使用cxf,spring,mybatis框架完成restful风格的webservice服务
- 【WebService框架-CXF】——CXF+Spring+Struts+自定义拦截器构建WebService客户端