WebService cxf 与 ssm框架的整合

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 = "paramsMap") 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";
    }

}



  




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值