码迷,mamicode.com
首页 > Web开发 > 详细

Apache CXF实现WebService开发(二)

时间:2014-12-14 15:56:24      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:spring   web.xml   apache   cxf   webservice   

       本文我们将承接上文Apache CXF实现WebService开发(一) http://blog.csdn.net/mahoking/article/details/41631993。完成将我们开发的WebService与我们的Web项目部署到同一个容器内例如Tomcat或JBOSS或其他的。本例我们使用的CXF的版本为apache-cxf-2.6.16。所使用是的相关jar包(文件)和文件所在的路径为:

/CXFWebServer/WebRoot/WEB-INF/lib/commons-logging-1.1.1.jar
/CXFWebServer/WebRoot/WEB-INF/lib/cxf-2.6.16.jar
/CXFWebServer/WebRoot/WEB-INF/lib/neethi-3.0.3.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-aop-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-asm-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-beans-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-context-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-core-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-expression-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/spring-web-3.0.7.RELEASE.jar
/CXFWebServer/WebRoot/WEB-INF/lib/wsdl4j-1.6.3.jar
/CXFWebServer/WebRoot/WEB-INF/lib/xmlschema-core-2.0.3.jar

【转载使用,请注明出处:http://blog.csdn.net/mahoking

       操作步骤为,创建Web Project项目CXFWebServer,本例需要的类User、IUserService、UserService。需要各位参考上文Apache CXF实现WebService开发(一) http://blog.csdn.net/mahoking/article/details/41631993。然后导入前文列出的相关的jar包(文件)。
1、 在/CXFWebServer/src下创建文件applicationContext-cxf.xml。

<?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">
	<!-- 【注】需要手动添加如下内容: xmlns:jaxws="http://cxf.apache.org/jaxws" 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" />

	<jaxws:endpoint id="userService" implementor="com.mahaochen.cxf.web.UserService"
		address="/userService" />

</beans>


2、 修改web.xml文件。

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
	
	<display-name>CXFWebServer</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext-cxf.xml</param-value>
	</context-param>
	
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<servlet>
		<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>/ws/*</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>

</web-app>


3、 将该项目CXFWebServer部署到Tomcat等服务器中。
4、 完成以上操作后,在浏览器中输入:
http://localhost:80/CXFWebServer/ws,出现如下。

bubuko.com,布布扣

5、出现上图就表示我们的操作与配置是成功的,最后就需要我们去使用WebService调用工具或者自己的客户端程序来测试我们的WebService的功能。

 

【转载使用,请注明出处:http://blog.csdn.net/mahoking

 

Apache CXF实现WebService开发(二)

标签:spring   web.xml   apache   cxf   webservice   

原文地址:http://blog.csdn.net/mahoking/article/details/41925029

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!