cxf+spring

web.xml 加入servlet节点

XML code
   
   
< servlet > < servlet-name > CXFServlet </ servlet-name > < servlet-class > org.apache.cxf.transport.servlet.CXFServlet </ servlet-class > < load-on-startup > 1 </ load-on-startup > </ servlet > < servlet-mapping > < servlet-name > CXFServlet </ servlet-name > < url-pattern > /service/* </ url-pattern > </ servlet-mapping >




applicatonContext-service :这是service层配置

XML code
   
   
<? 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:jee ="http://www.springframework.org/schema/jee" xmlns:tx ="http://www.springframework.org/schema/tx" xmlns:aop ="http://www.springframework.org/schema/aop" xsi:schemaLocation =" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" > <!-- 配置所有的Service层 --> < bean id ="functionFacade" class ="com.fendou.authority.service.impl.FunctionFacade" > < property name ="functionDao" > < ref bean ="functionDaoHibernate" ></ ref > </ property > < property name ="roleAuthFacade" > < ref bean ="roleAuthFacade" ></ ref > </ property > < property name ="functionHelper" > < ref bean ="functionHelper" ></ ref > </ property > < property name ="userAuthFacade" > < ref bean ="userAuthFacade" ></ ref > </ property > </ bean > < bean id ="functionHelper" class ="com.fendou.authority.service.impl.FunctionHelper" > < property name ="functionDao" > < ref bean ="functionDaoHibernate" ></ ref > </ property > </ bean > </ beans >



applicationContext-webservice:  
其中的jaxWsServiceFactoryBean可不配,默认是JAXB绑定,这里替换为aegis的绑定方式,比JAXB更加优化!

XML code
   
   
<? 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" > < 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" /> <!-- 通过Spring创建数据绑定的类 --> < bean id ="aegisBean" class ="org.apache.cxf.aegis.databinding.AegisDatabinding" /> < bean id ="jaxWsServiceFactoryBean" class ="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" > < property name ="wrapped" value ="true" /> < property name ="dataBinding" ref ="aegisBean" /> </ bean > < bean id ="jaxWsServiceFactoryBean2" class ="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" > < property name ="wrapped" value ="true" /> < property name ="dataBinding" ref ="aegisBean" /> </ bean > < jaxws:endpoint id ="functionFacadeService" implementor ="#functionFacade" address ="/functionFacadeService" > < jaxws:serviceFactory > < ref bean ="jaxWsServiceFactoryBean" /> </ jaxws:serviceFactory > </ jaxws:endpoint > < jaxws:endpoint id ="functionHelperService" implementor ="#functionHelper" address ="/functionHelperService" > < jaxws:serviceFactory > < ref bean ="jaxWsServiceFactoryBean2" /> </ jaxws:serviceFactory > </ jaxws:endpoint > </ beans >



IFunctionFacade 及FunctoinFacade
IFunctionHelper 及FunctionHelper 都只要在类前加@WebService这个注解


前台配置完成后用wsdl2java编译server端类放到client端:
client端 applicationContext-webservice.xm配置server端提供的服务bean

XML code
   
   
<? xml version="1.0" encoding="UTF-8" ?> < beans xmlns ="http://www.springframework.org/schema/beans" 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.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" > < jaxws:client id ="functionFacadeService" serviceClass ="com.fendou.authority.webservice.IFunctionFacade" address ="http://localhost:8080/HRB/service/functionFacadeService" /> < jaxws:client id ="functionHelperService" serviceClass ="com.fendou.authority.webservice.IFunctionHelper" address ="http://localhost:8080/HRB/service/functionHelperService" /> </ beans >



测试类:

Java code
   
   
package com.fendou.authority.test; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.fendou.authority.webservice.FunctionVO; import com.fendou.authority.webservice.GeneralException_Exception; import com.fendou.authority.webservice.IFunctionFacade; public class CXFTest { static IFunctionFacade functionFacade = null ; @BeforeClass public static void setUpBeforeClass() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext( " classpath:application/*/applicationContext-*.xml " ); functionFacade = (IFunctionFacade) context.getBean( " functionFacadeService " ); } // 创建服务 @Test public void testAdd() { functionFacade.sayHello( " xxx " ); FunctionVO funcVO = new FunctionVO(); funcVO.setFuncid( 2222222222l ); funcVO.setFuncName( " CRM管理平台 " ); funcVO.setParentFuncName( " CRM管理平台 " ); funcVO.setParentid( 2222222222l ); funcVO.setFuncUrl( " # " ); funcVO.setStatus( " 1 " ); try { functionFacade.addFunction(funcVO); } catch (GeneralException_Exception e) { e.printStackTrace(); } } }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值