cxf+spring发布webservice服务(服务器端)
创建需要暴露到webservice的接口及其实现
@WebService public interface HelloWorld { public String sayHello(String name); }
@WebService public class HelloWorldImpl implements HelloWorld { @Override public String sayHello(String name) { System.out.println("SayHello is called for " + name); return "Hello " + name; } }
在WEB-INF下新建beans.xlm文件
<?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-3.0.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"/> <!-- --> <jaxws:endpoint id="helloWorld" implementor="com.spg.testCxfSpring.impl.HelloWorldImpl" address="/Hello" /> <!-- <bean id="hello" class="com.spg.testCxfSpring.impl.HelloWorldImpl" /> <jaxws:endpoint id="helloWorld" implementor="#hello" address="/Hello" /> --> </beans>
其中import为引入cxf的配置
<jaxws:endpoint>标签配置cxf服务器数据,其中address采用相对地址
接下来配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <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> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
添加监听器,servlet配置等
此时服务器端已经发布成功,部署到tomcat中,启动tomcat,在浏览器中访问wsdl,http://localhost:8080/cxf-Spring-server/Hello?wsdl,成功访问说明webservice已经成功发布。
本文由用户 ymc4 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!