cxf spring 环境搭建
本文参考apache 官网:http://cxf.apache.org/
1.打开你所喜欢的IDE和创建了一个新的项目。我们要做的第一件事就是给项目添加必要的CXF依赖这个库文件。你能找到这些依赖分布在CXF库目录。
commons-logging-1.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.7.1.jar (or Sun's JavaMail jar) geronimo-servlet_3.0_spec-1.0.jar (or Sun's Servlet jar) geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181) jaxb-api-2.1.jar jaxb-impl-2.1.13.jar jaxws-api-2.1.jar neethi-3.0.0.jar saaj-api-1.3.jar saaj-impl-1.3.jar stax-api-1.0.1.jar stax2-api-3.1.1.jar wsdl4j-1.6.2.jar woodstox-core-asl-4.0.8.jar xmlschema-core-2.0.jar xml-resolver-1.2.jar
spring jar文件
aopalliance-1.0.jar spring-core-3.0.5.RELEASE.jar spring-beans-3.0.5.RELEASE.jar spring-context-3.0.5.RELEASE.jar spring-web-3.0.5.RELEASE.jar
添加cxf的jar文件
cxf-2.5.2.jar
2.写自己的service
首先,我们将先写我们的一个服务接口。它有一个 "sayHello" 方法为他传一个字符串的函数。
package demo.spring.service; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHi(String text); }
接下来我们实现这个方法。
package demo.spring.service; import javax.jws.WebService; @WebService(endpointInterface = "demo.spring.service.HelloWorld") public class HelloWorldImpl implements HelloWorld { public String sayHi(String text) { System.out.println("sayHi called"); return "Hello " + text; } }
在这个实现类上使用 @WebService 注解使cxf框架知道那个接口要被创建为wsdl。
这样下来我们就简单的创建了一个HelloWorld接口了。
3.在配置文件中生命服务bean
在beans.xml中使用 <jaxws:endpoint>标签来声明一个服务端的bean
<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-servlet.xml" /> <jaxws:endpoint id="helloWorld" implementor="demo.spring.service.HelloWorldImpl" address="/HelloWorld" /> </beans>
4.在web.xml里面配置cxfservlet 和 spring框架
<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>
<!-- cxfservlet --> <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>/*</url-pattern> </servlet-mapping> </web-app>
5.启动服务测试
启动tomcat 在浏览器端输入http://127.0.0.1:8080/MemberManage
访问查看发布的服务
相关推荐
newfarhui 2020-01-18
zhangxiaocc 2019-12-06
forliberty 2015-05-04
Adolphlwq 2017-08-10
newfarhui 2019-10-23
neweastsun 2013-12-07
Selier 2014-05-28
蜀川居 2017-10-16
jianghuchuanke 2019-09-05
zhongjcbill 2015-11-30
xiajlxiajl 2015-09-01
industry0 2014-12-08
cloudspring 2014-11-29
bobobocai 2014-07-17
LunaZhang 2012-06-11
89467606 2015-12-25
iPro 2014-05-28
LunaZhang 2011-09-14
chenhualeguan 2011-11-30