Spring整合CXF
来源:互联网 发布:arm单片机介绍 编辑:程序博客网 时间:2024/06/04 17:45
1.建工程添jar包改配置,用myeclipse自带的spring插件完成构建。
说明:先用自带的完成,然后删除jia包重新添加进去我们自己准备的jia包,目的是为了用自动生成的web.xml和applicationContext.xml。
2.修改applicationContext.xml,参考前一页PPT官网。
<?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: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-3.1.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<jaxws:endpoint id="helloworld" implementor="com.atguigu.cxf.spring.HelloWorldImpl" address="/HelloWorld"></jaxws:endpoint>
</beans>
3.修改web.xml 关键类:org.apache.cxf.transport.servlet.CXFServlet
<?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_2_5.xsd"
id= "WebApp_ID" version ="2.5">
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener</listener-class >
</listener>
<context-param>
<param-name> contextConfigLocation</param-name >
<param-value> classpath:applicationContext.xml</param-value >
</context-param>
<servlet>
<servlet-name> cxf01</ servlet-name>
<servlet-class> org.apache.cxf.transport.servlet.CXFServlet</servlet-class >
</servlet>
<servlet-mapping>
<servlet-name> cxf01</ servlet-name>
<url-pattern> /services/*</url-pattern >
</servlet-mapping>
</web-app>
4.我们的代码:
(1) 接口
import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebResult;import javax.jws.WebService;@WebServicepublic interface HelloWorld{ @WebMethod @WebResult(name = "sayHelloResult") public String sayHello(@WebParam(name = "userName") String name,@WebParam(name = "userAge") int age);}
(2) 实现类
import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebResult;public class HelloWorldImpl implements HelloWorld{ @Override @WebMethod @WebResult(name = "sayHelloResult") public String sayHello(@WebParam(name = "userName") String name,@WebParam(name = "userAge") int age) { return "spring say hello to: " + name + "\t" + "age: " + age; }}
5.整合:
将以上的项目部署到Tomcat中进行启动,在浏览器端输入:http://localhost:8080/cxf_spring/services 页面出现wsdl文件访问路径,点击进去,如果有wsdl报文出现,就证明部署成功。
说明:这样做service端就可以,打成jia包直接就可以供其他人调用了。
PS:若想结合源码更好的理解WebService,请:https://github.com/luomingkui/WebService
阅读全文
0 0
- 五、CXF整合Spring
- CXF整合Spring
- CXF WebService整合Spring
- Spring 整合 CXF
- CXF整合Spring入门教程
- CXF WebService整合Spring
- CXF WebService整合Spring
- cxf和spring整合
- spring+cxf+bonecp整合
- CXF WebService整合Spring
- CXF Spring整合案例
- CXF WebService整合Spring
- cxf和spring整合
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- cxf 与 spring整合
- CXF整合spring
- Error: Failed to create the site. The machine does not have a valid license. Please authorize ArcGIS
- [模板练习]线性筛素数
- bzoj 1142: [POI2009]Tab 乱搞
- 舍利子的身世
- ajax注意问题
- Spring整合CXF
- 阿里2017暑期实习内推面经
- php源码编译安装
- 数据结构与算法
- dpdk ring 性能测试
- 交警罚没系统数据一致性问题
- Shell杂记
- 滴滴新锐计划实习生面试经历
- poj3414(bfs)