WebService cxf 与 ssm框架的整合
2017-07-24 10:30
344 查看
1、配置文件: (1)spring-cxf.xml <?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.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"/> <jaxws:server id="getInfoService" address="/getInfoService" serviceClass="com.sojson.zhifu.service.GetInfoService"> <jaxws:serviceBean> <bean class="com.sojson.zhifu.service.impl.GetInfoServiceImpl"></bean> </jaxws:serviceBean> <jaxws:inInterceptors> <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean> </jaxws:inInterceptors> <jaxws:outInterceptors> <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean> </jaxws:outInterceptors> </jaxws:server> </beans> (2)spring-cxf-client.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <context:property-placeholder location="classpath:url.properties"/> <jaxws:client id="userWsClient" serviceClass="com.sojson.zhifu.service.GetInfoService" address="http://192.168.3.125:8080/chuangxinpay/ws/getInfoService?wsdl" /> </beans> (3)spring.xml <?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <!-- 引入属性文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <value>classpath:jdbc.properties</value> <value>classpath:config.properties</value> <value>classpath:shiro-config.properties</value> </list> </property> </bean> <import resource="spring-mybatis.xml"/> <import resource="spring-cache.xml"/> <import resource="spring-shiro.xml"/> <!-- 引入cxf文件 --> <import resource="spring-cxf.xml"/> <import resource="spring-cxf-client.xml"/> <!-- 定时任务,运行去掉 <import resource="spring-timer.xml"/> --> </beans> (4)web.xml <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring.xml</param-value> </context-param> <servlet> <servlet-name>CXFService</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXFService</servlet-name> <url-pattern>/ws/*</url-pattern> </servlet-mapping> 2、java文件 (1)model.java package com.sojson.zhifu.model; import java.io.Serializable; public class RetInfo implements Serializable{ private static final long serialVersionUID = 4855234345398416636L; private String name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } (2)service.java package com.sojson.zhifu.service; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import com.sojson.zhifu.model.RetInfo; @WebService public interface GetInfoService { @WebMethod(operationName = "add") @WebResult(name = "result") public int add(@WebParam(name = "num1") int num1, @WebParam(name = "num2") int num2); @WebMethod(operationName = "getRetInfo") @WebResult(name = "result") public RetInfo getRetInfo(@WebParam(name = "name") String name, @WebParam(name = "age") int age); /** * 下载面试人的信息 */ @WebMethod(operationName = "downloadCandidateInfo") @WebResult(name = "result") RetInfo downloadCandidateInfo(@WebParam(name = "name") String name); /** * 获取客户端传过来的参数,校验参数是否正确, 如果正确返回一个支付二维码页面,如果不正确,报错 */ @WebMethod(operationName ="getClientInformation") @WebResult(name ="result") public String getClientInformation(@WebParam(name = "para b081 msMap") String paramsMap); } (3)GetInfoServiceImpl.java package com.sojson.zhifu.service.impl; import javax.jws.WebService; import com.sojson.zhifu.model.RetInfo; import com.sojson.zhifu.service.GetInfoService; @WebService(endpointInterface = "com.sojson.zhifu.service.GetInfoService") public class GetInfoServiceImpl implements GetInfoService { @Override public int add(int num1, int num2) { // TODO Auto-generated method stub return num1 + num2; } @Override public RetInfo getRetInfo(String name, int age) { // TODO Auto-generated method stub RetInfo retInfo = new RetInfo(); retInfo.setAge(age); retInfo.setName(name); System.out.println("信息:" + retInfo.getAge() + ":::" + retInfo.getName()); return retInfo; } /** * @param name * @return * * @author Administrator Jul 19, 2017 4:13:08 PM * @version 1.0 */ @Override public RetInfo downloadCandidateInfo(String name) { RetInfo ci = new RetInfo(); if(name.trim().equals("tz")){ ci.setName("tz"); } else{ ci.setName("Kevin"); } System.out.println("ci==" + ci.getName()); return ci; } /** * @param paramsMap * @return * * @author Administrator Jul 20, 2017 10:11:31 AM * @version 1.0 */ @Override public String getClientInformation(String paramsMap) { System.out.println("客户端传过来的参数:" + paramsMap); return "success"; } }
相关文章推荐
- cxf框架整合ssm框架案例
- webservice学习之cxf框架-spring整合
- WebService(注解),CXF框架(jax-ws,Jax-rs,与spring整合)
- 框架 day64 WebService(注解),CXF框架(jax-ws,Jax-rs,与spring整合)
- WebService技术中CXF框架与Spring整合和常见bug
- 【笔记】WebService CXF与SSM整合,模拟实名认证功能
- WebService中CXF的简单的配置和应用(ssm框架)
- spring和cxf框架整合实现webService服务
- WebService的CXF框架与Spring的整合发布服务入门
- WebService的CXF框架整合Spring
- 用cxf框架在ssm架构中发布webservice
- spring boot整合cxf发布webservice服务和cxf客户端调用
- 手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis
- ssm整合shiro框架
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- 手把手教你整合最优雅SSM框架:SpringMVC + Spring + MyBatis
- SSM框架(一)之SSM框架整合(Spring,SpringMVC,MyBatis)
- SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)【转】
- SSM框架整合和mybatis generator应用
- Spring 集成CXF框架发布Webservice服务 和 使用jdk生成Webservice clinet