cxf +spring 发布webservice
1.导入cxf jar包集成了spring jar \apache-cxf-2.4.2\apache-cxf-2.4.2\lib 所以jar
2.web.xml 如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" 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_2_5.xsd"> <!-- 配置spring 监听器 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:cxf-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置CXF的核心Servlet --> <servlet> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <!-- 通过初始化参数指定cxf配置文件的位置 --> <!-- <init-param> <param-name>config-location</param-name> <param-value>classpath:cxf-servlet.xml</param-value> </init-param> --> </servlet> <servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/cxf/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
3.编写服务端代码
package cn.my.cxf; import javax.jws.WebService; import javax.xml.ws.BindingType; import javax.xml.ws.soap.SOAPBinding; //别忘了加注解 @WebService public class HelloService { public String sayHello(String name){ System.out.println("正在调用sayHello方法"); return "hello " + name; } }
4.spring配置文件如下:
<?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" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> <!-- 引入CXF Bean定义如下,早期的版本中使用 --> <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" /> <!-- 第一种发布方式:简单发布(没有接口的发布) --> <!-- id:唯一标示 implementor:提供服务的类 address:服务的请求url--> <jaxws:endpoint id="helloService" implementor="cn.my.cxf.HelloService" address="/hello"> </jaxws:endpoint> </beans>
5.访问wsdl
成功
相关推荐
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
bobobocai 2014-07-17
LunaZhang 2012-06-11
89467606 2015-12-25
iPro 2014-05-28
LunaZhang 2011-09-14
chenhualeguan 2011-11-30
青青木屋 2019-07-01