Apache CXF = Celtix + XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-WS 全面的支持,并且提供了多种 Binding 、DataBinding、Transport 以及各种 Format 的支持,并且可以根据实际项目的需要,采用代码优先(Code First)或者 WSDL 优先(WSDL First)来轻松地实现 Web Services 的发布和使用。Apache CXF已经是一个正式的Apache顶级项目。
1.在web.xml添加cxf对应的servlet
<servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/data/ws/*</url-pattern> </servlet-mapping>
当我们输入http://locahost:8080/test/date/ws/,我们就能看到web下的所有webservice。
2.定义WEBService接口及实现
package com.vcredit.jdev.obiz.account.controller; import java.net.MalformedURLException; import javax.jws.WebParam; import javax.jws.WebService; import com.vcredit.jdev.obiz.ws.entity.CommonContent; import com.vcredit.jdev.obiz.ws.entity.LoginContent; import com.vcredit.jdev.obiz.ws.entity.WSResponse; /** * @ClassName: AccountWebService * @Description: TODO(account module WebServcie interface CXF ?wsdl) * @author dk * @date 2014年8月18日 下午1:36:17 * */ @WebService public interface AccountWebService { public WSResponse<LoginContent> login(@WebParam(name="loginName") String loginName,@WebParam(name="password")String password); public WSResponse<CommonContent> addLoginAccount(@WebParam(name="username") String username,@WebParam(name="mobile") String mobile,@WebParam(name="password") String password,@WebParam(name="verifyCode") String verifyCode) throws Exception; public WSResponse<CommonContent> updatePassword(@WebParam(name="username") String username,@WebParam(name="secureCode") Long secureCode,@WebParam(name="oldPassword") String oldPassword,@WebParam(name="newPassword") String newPassword); public WSResponse<CommonContent> resetPassword(@WebParam(name="mobile") String mobile,@WebParam(name="newPassword") String newPassword,@WebParam(name="verifyCode") String verifyCode); public WSResponse<CommonContent> checkCellPhone(@WebParam(name="mobile") String mobile); public WSResponse<CommonContent> checkVerifyCode(@WebParam(name="mobile") String mobile,@WebParam(name="verifyCode") String verifyCode); public WSResponse<CommonContent> sendVerifyCode(@WebParam(name="mobile") String mobile) throws MalformedURLException; }
实现类:
package com.vcredit.jdev.obiz.account.controller; import java.net.MalformedURLException; import javax.jws.WebService; import net.gplatform.sudoor.server.security.model.auth.SSAuth; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.vcredit.jdev.obiz.account.model.Login; import com.vcredit.jdev.obiz.account.model.PasswordReset; import com.vcredit.jdev.obiz.account.model.PhoneService; import com.vcredit.jdev.obiz.account.model.Register; import com.vcredit.jdev.obiz.account.model.entity.Account; import com.vcredit.jdev.obiz.base.BaseConstants; import com.vcredit.jdev.obiz.ws.entity.CommonContent; import com.vcredit.jdev.obiz.ws.entity.LoginContent; import com.vcredit.jdev.obiz.ws.entity.WSResponse; @Component @WebService public class AccountWebServiceImpl implements AccountWebService { private Logger logger = LoggerFactory.getLogger(AccountWebServiceImpl.class); @Autowired private SSAuth auth; @Autowired private Register register; @Autowired private Login login; @Autowired private PasswordReset passwordReset; @Autowired private PhoneService phoneService; @Override public WSResponse<LoginContent> login(String loginName, String password) { if(StringUtils.isBlank(loginName)){ return WSResponse.errorResponse(new LoginContent(false, "-2",-1L,"UserKind",-1L)); } if(StringUtils.isBlank(password)){ return WSResponse.errorResponse(new LoginContent(false, "-2",-1L,"UserKind",-1L)); } Account account = register.getAccountByLoginName(loginName); if(account != null){ auth.authenticate(account.getId().toString(), password); }else{ return WSResponse.errorResponse(new LoginContent(false, "-2",-1L,"UserKind",-1L)); } return WSResponse.successResponse(new LoginContent(true, "2", account.getId(), "UserKind", 1L)); } } 。。。。。
@WebService
@WebParam(name="loginName") 参数的设置,明确参数。当不设置,会出现arg0,arg1的表示参数
3.在spring.xml添加Bean
<?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.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:endpoint id="accountServiceEndPoint" implementor="#accountServiceImpl" address="/soap/account/accountService" /> <jaxws:endpoint id="loginService" implementor="#loginServiceImpl" address="/soap/account/loginService" /> <jaxws:endpoint id="newConsumerService" implementor="#newConsumerServiceImpl" address="/soap/account/newConsumerService" /> <jaxws:endpoint id="featureService" implementor="#featureServiceImpl" address="/soap/account/featureService" /> <jaxws:endpoint id="userService" implementor="#userServiceImpl" address="/soap/account/userService" /> <jaxws:endpoint id="accountWebService" implementor="#accountWebServiceImpl" address="/soap/account/accountWebService" /> <jaxws:client id="accountServiceClient" serviceClass="com.vcredit.jdev.obiz.example.controller.AccountService" address="http://localhost:8080/obiz/data/ws/soap/account/accountService" /> </beans>
4.pom.xml
<properties> <cxf.version>3.0.0</cxf.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf.version}</version> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <includes> <include>*.wsdl</include> </includes> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-ws-security</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxrs</artifactId> <version>${cxf.version}</version> </dependency>
相关推荐
Spring集成Cxf调用WebServices
Struts+spring集成cxf的ws与rs 实现多样化能力,基于HTTP、SOAP、Action
Spring集成CXF实例(包含WSS4J安全认证)
Spring集成Cxf暴露WebServices示例
使用spring集成cxf,在两个web project里发布及调用webservice server端使用spring+springmvc+mybatis+cxf,client端使用struts2+spring+hibernate+cxf 两个工程均为myeclipse project,包含所有除myeclipse自带以外...
spring4+cxf3,因为自己项目要用到接口开发,所以综合现有网上所有教程,终于成功写出能自动注入的demo,这个是含拦截器
spring4+cxf3,因为自己项目要用到接口开发,所以综合现有网上所有教程,终于成功写出能自动注入的demo
Web Service是一种构建应用程序的普遍模型,可以在任何支持网络通信的操作系统中实施运行;它是一种新的webs应用程序分支,是自包含、自描述、模块 化的应用,可以发布、定位、通过web调用。
源代码 博文链接:https://qsx1982-126-com.iteye.com/blog/629191
webService实现 cxf2.7.5 与 spring3.0集成 完整流程,内涵全部jar ,下载集合运行
NULL 博文链接:https://yingzhuo.iteye.com/blog/1893401
Spring整合CXF例子.项目里面带有Jar包.有自己写的注释.下载即可运行.不懂的可以问我
NULL 博文链接:https://a52071453.iteye.com/blog/1675822
主要给大家介绍了关于spring如何集成cxf实现webservice接口功能的相关资料,文中通过示例代码介绍的非常详细,对大家 的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧
cxf与spring整合webservice所需jar
用于webservice的开发,主要用到spring+cxf的方式实现webservice的发布与简单调用测试,不懂得可以留言给我,比较显新的框架配置,希望你会喜欢!(并包含拦截器的配置!)
spring3.2.14集成CXF3.0完整版,下载之后部署到tomcat8.0中即可运行,不需要更多配置,适合新手研究学习。
spring+cxf 集成 实现webservice
好东西要大家一起分享,这个绝对是最新的,最好的!