在spring环境下利用axis发布服务的初体验

来源:互联网 发布:聚乙烯塑料有毒吗 知乎 编辑:程序博客网 时间:2024/04/29 08:54

1、作为web服务的类最好简单,不要有太多继承关系,否则有许多意想不到的麻烦,比如继承hibernatesupport,在发布的时候就会遇到

sessionfactory不能序列化的问题等
2、在部署时 allowedmethod里面最好不要用*号,最好依次填上所有需要的方法,以免在部署set get方法时遇到参数对象不能被序列化的问题

(setUserDao)
3、要是web服务的类能够和spring环境一起工作,有一些额外的工作要做(真他妈麻烦)
web服务的提供类必须有spring管理,因此在调用web服务时需要从web应用环境中去的代表服务类的bean,完成这一步用到了一个开放源代码组

织提供的几个类http://opensource.atlassian.com/projects/spring/browse/SPR-371
SpringAxisServlet.java,SpringBeanProvider.java,SpringBeanRPCPrvider.java
SpringAxisServlet:继承自AxisServlet,用来加载spring的context,SpringBeanProvier运行的前提
SpringBeanProvider:用于获取spring context中的bean
SpringBeanRPCProvider:调用SpringBeanProvider来获得通过Spring IoC注入后的web 服务bean
4、在配置时需要注意的几点
 a、在web.xml中增加如下配置
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/AxisServlet-servlet.xml</param-value>
  </context-param>

  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>com.workingmouse.webservice.axis.SpringAxisServlet</servlet-class>
  </servlet>

    <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>
====具体把axis和应用环境集成起来的配置还有更多的没有写出来==========
 b、在server-config.wsdd中如下配置service
 <service name="SomeService"  provider="Handler" style="rpc">
  <parameter name="handlerClass"     value="com.workingmouse.webservice.axis.SpringBeanRPCProvider"/>
  <parameter name="springBean" value="SomeService"/>

  <parameter name="allowedMethods" value="*"/>
 </service>
 c、在spring配置文件AxisServlet-servlet.xml中添加一下内容
 <bean id="SomeService" class="cn.boyoi.webservice.SomeService">
  <property name="userDao"><ref local="userDao"/></property>
 </bean>
5、以下是一个简单服务的代码 userDao通过spring IoC注入
package cn.boyoi.webservice;
import cn.boyoi.dao.*;
public class SomeService {
 //=================attributes use spring IoC====================//
 private UserDao userDao;
 
 //=====================write method=============================//
 public void setUserDao(UserDao userDao)
 {
  this.userDao = userDao;
 }
 //===================web service method=========================//
 public boolean checkUser(String username,String password)
 {
  return userDao.checkUser(username,password);

 }


}

============感谢牛人,不然我就郁闷了.....=============