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;}}
<?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>
<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>