首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

WebService服务端——CXF跟Spring的整合

2013-07-04 
WebService服务端——CXF和Spring的整合一、在Spring开发环境的基础上导入Jar包:- cxf.jar - commons-logging

WebService服务端——CXF和Spring的整合
一、在Spring开发环境的基础上导入Jar包:
- cxf.jar
- commons-logging.jar
- neethi.jar
- XmlSchema.jar
- wsdl4j.jar

二、创建WebService接口

package com.demo;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface HelloWorld {public String sayHi(@WebParam(name = "text") String text);}

三、编写实现类
package com.demo;import javax.jws.WebService;@WebService(endpointInterface = "com.demo.HelloWorld", serviceName = "HelloWorld")public class HelloWorldImpl implements HelloWorld {public String sayHi(String text){return "Hello "+text;}}

四、配置application-context.xml
<?xml version="1.0" encoding="UTF-8"?><beans    default-autowire="byName"xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://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="helloWorld"              implementor="com.demo.HelloWorldImpl"              address="/helloWorld" /></beans>

五、web.xml中加入如下配置
<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>/webservice/*</url-pattern></servlet-mapping><context-param>

六、启动Tomcat,访问http://localhost:8080/YHPC/webservice/helloWorld?wsdl查看是否配置成功。

热点排行