使用Spring+CXF开发WebService
Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services
各种类型的Annotation。@WebService和@WebMethod是WSDL映射Annatotion。这些Annotation将描述Web Service的WSDL文档元素和Java源代码联系在一起。
@SOAPBinding是一个绑定的annotation用来说明网络协议和格式。
1、@WebService annotation的元素name,serviceName和targetNamespace成员用来描述
wsdl:portType,wsdl:service,和targetNameSpace生成WebService中的WSDL文件。
2、@SOAPBinding是一个用来描述SOAP格式和RPC的协议的绑定Annotation。
3、@WebMethod Annotation的operationName成员描述了wsdl:operation,而且它的操作描
述了WSDL文档中的SOAPAction头部。这是客户端必须要放入到SQAPHeader中的数
值,SOAP 1.1中的一种约束。
4、@WebParam Annotation的partName成员描述了WSDL文档中的wsdl:part。
5、@WebResult Annotation的partName成员描述了wsdl:part用来返回WSDL文档的值。
例如下面使用annotation定义了一个webservice:
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import com.cxf.pojo.User;
@WebService(targetNamespace = "http://jdk.study.hermit.org/client")
public interface UserService {
@WebMethod(operationName="Insert")
public void insert( @WebParam(name = "userId") String userid,
@WebParam(name = "userName") String username,
@WebParam(name = "userEmail") String useremail,
@WebParam(name = "userAge") int userage);
@WebMethod(operationName="GetUserById")
@WebResult(name = "result")
public User getUserById(@WebParam(name="userid") String userid);
@WebMethod(operationName="GetAllUsers")
@WebResult(name = "result")
public List getAllUsers();
}
其实现类如下所示:
import java.util.List;
import javax.jws.WebService;
import com.cxf.dao.UserDao;
import com.cxf.pojo.User;
import com.cxf.service.UserService;
@WebService(endpointInterface="com.cxf.service.UserService")
public class UserServiceImpl implements UserService {
private UserDao userDao;
public List getAllUsers() {
return userDao.findAllUser();
}
public User getUserById(String userid) {
return userDao.findUserById(userid);
}
public void insert(String userid, String username, String useremail, int userage) {
User user=new User();
user.setUserage(userage);
user.setUseremail(useremail);
user.setUserid(userid);
user.setUsername(username);
userDao.insert(user);
System.out.println("insert successfully!");
}
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
}
注意:实现类中的@WebService,其中的endpointInterface成员指定了该类实现的接口
在Spring的配置文件中,需要对其进行配置:
首先在ApplicationContext.xml(Spring的配置文件)中引入CXF的XML Scheam 配置文件),如下:
<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">
<!—还需要引入以下3个关于CXF的资源文件,这三个文件在cxf.jar中-->
<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" />
…… …… …… …… …… …… …… …… …… ……
</bean>
其次就是在Spring的配置文件中配置webservice,如下所示:
<jaxws:endpoint id="userManager" address="/UserManager"
implementorClass="com.cxf.service.UserService">
转载于:https://blog.51cto.com/alinazh/1276313
使用Spring+CXF开发WebService相关推荐
- spring+cxf 开发webService(主要是记录遇到spring bean注入不进来的解决方法)
这里不介绍原理,只是记录自己spring+cxf的开发过程和遇到的问题 场景:第三方公司需要调用我们的业务系统,以xml报文的形式传递数据,之后我们解析报文存储到我们数据库生成业务单据: WebSer ...
- Spring+CXF开发WebService
ps:所有源码下载地址: http://download.csdn.net/download/gaowenhui2008/7977097 准备工作: 下载spring,apache-cxf,soapU ...
- cxf开发webservice服务端怎么返回固定的报文格式_Spring boot webservice怎么玩? 第277篇...
相关历史文章(阅读本文之前,您可能需要先看下之前的系列?) WebService SOAP概述 - 第275篇 WSDL是什么"Lese" - 第276篇 一.前言 当官不为民做主 ...
- 使用cxf开发webservice应用时抛出异常
在使用cxf开发webservice应用时,报出了类似下面的错误 JAXB: [javax.xml.bind.UnmarshalException: unexpected element (uri:& ...
- Java笔记-使用CXF开发WebService服务器
这里使用CXF开发WebService,要引入下面这个Maven <dependency><groupId>org.apache.cxf</groupId>< ...
- Spring boot+CXF开发WebService Demo
本文转载自: https://www.cnblogs.com/fuxin41/p/6289162.html 作者:fuxin41 转载请注明该声明. 最近工作中需要用到webservice,而且结合s ...
- CXF开发WebService服务器端
开发必备 1.apache-cxf-2.2.6 2.spring-ws-1.5.8 3.eclipse-jee-galileo-SR1-win32 开发步骤: 一.新建一个Dynamic Web Pr ...
- 使用CXF开发webService客户端
注:csdn排版太麻烦,放在git上了. 地址:https://github.com/liangjuntao/cxf_spring_struts.git Web Service简介: 不是一种框架.更 ...
- WebService开发笔记 1 -- 利用cxf开发WebService竟然如此简单
现在的项目中需要用到SOA概念的地方越来越多,最近我接手的一个项目中就提出了这样的业务要求,需要在.net开发的客户端系统中访问java开发的web系统,这样的业务需求自然需要通过WebService ...
最新文章
- p沟道mos管导通条件_10天电子入门-MOS管
- Axure原型尺寸笔记
- python生成器和迭代器作用_浅谈Python中的生成器和迭代器
- 作为一枚学生党,如何提升自己华丽转身
- JavaSE、JavaEE、JavaME、jdk、jre、jvm、java主要的11个特性
- ARM中LDR伪指令与LDR加载指令
- EFCore废弃了TransactionScope取而代之的Context.Database.BeginTransaction
- 1 0.99999的悖论_无限小数与芝诺悖论
- ajax动态获取url参数值,获取URL参数的方法
- ocp oracle 考试报名_获得Oracle认证对拓展职业前景的影响
- Flutter 开发应用第一个页面
- SSH+Oracle10G抛Disabling contextual LOB creation as createClob() m
- MySQL字符串转日期
- 本篇文章使用vue结合element-ui开发tab切换vue的不同组件,每一个tab切换的都是一个新的组件。
- Opencv之获取边缘和画轮廓
- Redis 可视化工具 Redis Desktop Manager 和 treeNMS 的使用
- 使用Python解二元一次方程组
- ajax readystate为1,Ajax readyState总是等于1
- get、put、post、delete四大请求的含义与区别个人理解和解释
- 【HDU 5765】Bonds(进制运算妙用)