cxf 在做企业级webservices 服务的时候确实非常好用,个人觉得比axis1, 2都好用。

虽然spring自身也提供了webservices发布方法,这里使用cxf跟spring结合,使用起来非常方便;


整体项目结果如下:

基于maven 来配置使得项目更加简单

  1. 新建一个maven 项目,补全 src下的main和test目录

  2. 打开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" 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">
<display-name>cxf</display-name>
<servlet>
<description>m CXF Endpoint</description>
<display-name>cxf</display-name>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
  1. 新建一个cxf-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: beans -->
<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.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-servlet.xml"/>
<jaxws:endpoint id="DepartmentService" implementor="com.qycloud.oatos.ty.department.DepartmentServiceImpl" address="/DepartmentService"/>
<jaxws:endpoint id="UserService" implementor="com.qycloud.oatos.ty.user.UserServiceImpl" address="/UserService"/>
</beans>
  1. 补全 pom.xml ,主要是spring 的依赖和cxf,cxf 只需要以下2个
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.0</version>
</dependency>
  1. 编写代码:这里我们回头看到cxf-servlet.xml 里面可发现我们只需要制定一个id,一个是实现类,一个访问地址即可。

a) 编写一个接口

@WebService
public interface DepartmentService { boolean updateTheOrg(String org); boolean updateOrgsCode(String org); }

b) 编写一个实现类

@WebService(endpointInterface = "com.qycloud.oatos.ty.department.DepartmentService")
public class DepartmentServiceImpl implements DepartmentService { @Override
public boolean updateTheOrg(String org) {
// TODO Auto-generated method stub
return false;
} @Override
public boolean updateOrgsCode(String org) {
// TODO Auto-generated method stub
return false;
} }

7.剩下的事情就是发布了。右键run on server。结果如下

  1. demo下载地址

最新文章

  1. hibernate学习笔记之二 基本环境搭建
  2. MongoDB学习笔记—Linux下搭建MongoDB环境
  3. .NET 类型(Types)的那些事
  4. DbContext 和ObjectContext两者的区别
  5. Web API数据传输加密
  6. 从C#到Objective-C,循序渐进学习苹果开发(5)--利用XCode来进行IOS的程序开发
  7. java课后作业
  8. Spring源码学习之:ClassLoader学习(4)
  9. Linux下配置Tomcat服务器
  10. eval(gzinflate(base64_decode N层,自动解密
  11. [原创]java WEB学习笔记53:Struts2学习之路---前奏:使用 Filter 作为控制器的 MVC
  12. ADO.NET增删改-------跟查不一样
  13. dat文件中如何编写DOS的多行命令
  14. 51nod 1336 RMQ逆问题
  15. Call与Apply
  16. Catalyst揭秘 Day4 analyzer解析
  17. 字符串转到js对象
  18. 编译的时候 c:\windows\assembly\ 卸载不掉
  19. BZOJ 1230: [Usaco2008 Nov]lites 开关灯( 线段树 )
  20. ES6-map、filter、find、findIndex讲解

热门文章

  1. angular源码分析:$compile服务——directive他妈
  2. position: fixed用在iframe里面失效了
  3. sharePoint 2016 弃用和删除的功能
  4. UIButton
  5. iOS开发之功能模块--高仿Boss直聘的常用语的开发
  6. 我们为什么要使用maven,公司推行maven杂谈
  7. Git的冲突解决过程
  8. Java源码分析之LinkedList
  9. Java:Remote Debug
  10. Python进阶【第二篇】多线程、消息队列queue