shh+axis

1、首先,需要axis2.war,根据它的目录结构我们修改自己的web应用。只需拷贝axis2/WEB-INF/目录下的所有文件到自己的web项目下就可以了,记得要覆盖所有(axis2-web这个文件夹是包含axis2整个的管理界面,可有可无,不过要用的话,记得它是放在和WEB-INF的同级目录下),其实我们就是有点像在整个的axis2工程上做二次开发。

2、我们像做所有其它的Web项目一样,用到spring的时候拷贝spring.jar到WEB-INF/lib目录下,然后在web.xml同级的目录下建立一个 applicationContext.xml,并且在applicationContext.xml引用相应的DTD或XSD(spring1.2引用 的是DTD,spring2.0引用的是XSD),然后会在web.xml中加入这一段(当然,你可以选择用其它方式配置spring对web项目的支 持)。
Java代码 复制代码  收藏代码
  1. <listener >   
  2.      <listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >   
  3. </listener >   
  4. <context-param >   
  5.      <param-name > contextConfigLocation </ param-name >   
  6.      <param-value > /WEB-INF/applicationContext.xml </ param-value >   
  7. </context-param >  
  <listener >
       <listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
  </listener >
  <context-param >
       <param-name > contextConfigLocation </ param-name >
       <param-value > /WEB-INF/applicationContext.xml </ param-value >
  </context-param >


3、发布整个项目发部到tomcat上,测试起动服务有没有问题。(一般不会是有问题,我们现在做的只是在axis2这个工程里添加了spring的jar包和在原有的axis2工程的web.xml加上了对spring的支持)。起动没问题的话就访问下http://<host>:<port>/<project name>/services/Version?wsdl,只要成功就可以了,下面进入正题。


4、写一个接口。(体现spring面向接口编程的好处)
Java代码 复制代码  收藏代码
  1. package com.hp.bean;   
  2. public   interface  MyBean {   
  3.      public  String echo();   
  4. }  
package com.hp.bean;
public   interface  MyBean {
     public  String echo();
}



5、实现这个接口。
Java代码 复制代码  收藏代码
  1. package com.hp.bean;   
  2. public   class  MyBeanImpl implements MyBean {   
  3.      public  String echo() {   
  4.            
  5.          return   "Merry" ;   
  6.     }   
  7. }  
package com.hp.bean;
public   class  MyBeanImpl implements MyBean {
     public  String echo() {
        
         return   "Merry" ;
    }
}



6、写一个Web Service
Java代码 复制代码  收藏代码
  1. package com.hp.service;   
  2. import com.hp.bean.MyBean;   
  3. public   class  SpringAwareService {   
  4.      private  MyBean myBean;   
  5.      public   void  setMyBean(MyBean myBean) {   
  6.          this .myBean = myBean;   
  7.     }   
  8.        
  9.      public  String response(){   
  10.            
  11.          return  myBean.echo() +  " Christmas!" ;   
  12.     }   
  13. }  
package com.hp.service;
import com.hp.bean.MyBean;
public   class  SpringAwareService {
     private  MyBean myBean;
     public   void  setMyBean(MyBean myBean) {
         this .myBean = myBean;
    }
    
     public  String response(){
        
         return  myBean.echo() +  " Christmas!" ;
    }
}


7、编写applicationContext.xml.(记住第一个bean,也就是applicationContext那个一定要有)
Java代码 复制代码  收藏代码
  1. <bean id= "applicationContext"  
  2.      class = "org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"  />   
  3. <bean id= "springAwareService"  
  4.      class = "com.hp.service.SpringAwareService" >   
  5.     <property name= "myBean"   ref = "myBean"  />   
  6. </bean>   
  7. <bean id= "myBean"   class = "com.hp.bean.MyBeanImpl" ></bean>  
    <bean id= "applicationContext"
         class = "org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"  />
    <bean id= "springAwareService"
         class = "com.hp.service.SpringAwareService" >
        <property name= "myBean"   ref = "myBean"  />
    </bean>
    <bean id= "myBean"   class = "com.hp.bean.MyBeanImpl" ></bean>

8、在WEB-INF/services/下新建一个文件夹,这个名字可以起的随便,我们就起做test吧,然后在WEB-INF/services/test/下建立META-INF这个目录,最后在WEB-INF/services/test/META-INF/下建立service.xml,文件内容是:
Java代码 复制代码  收藏代码
  1. <service name= "SpringAwareService" >   
  2.     <description>simple spring example</description>   
  3.     <parameter name= "ServiceObjectSupplier" >   
  4.         org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier   
  5.     </parameter>   
  6.     <parameter name= "SpringBeanName" >springAwareService</parameter>   
  7.     <messageReceivers>   
  8.         <messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-only"  
  9.              class = "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"  />   
  10.         <messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-out"  
  11.              class = "org.apache.axis2.rpc.receivers.RPCMessageReceiver"  />   
  12.     </messageReceivers>   
  13. </service>  
<service name= "SpringAwareService" >
    <description>simple spring example</description>
    <parameter name= "ServiceObjectSupplier" >
        org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
    </parameter>
    <parameter name= "SpringBeanName" >springAwareService</parameter>
    <messageReceivers>
        <messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-only"
             class = "org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"  />
        <messageReceiver mep= "http://www.w3.org/2004/08/wsdl/in-out"
             class = "org.apache.axis2.rpc.receivers.RPCMessageReceiver"  />
    </messageReceivers>
</service>

这回再发布一下,在没有异常的情况下。访问一下http://<host>:<port>/<project name>/services/SpringAwareService?wsdl 看看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值