axis2 开发

1,如果是单独开发,。axis2支持pring的装载,具体参见官方文档。但如果采用完整aar的方式(即你的程序和依赖jar都打到aar里)则因为class loader的原因需要注意两点:
1.需要吧axis2/WEB-INF/lib/axis2-spring-1.4.jar删除
2.需要配置hibernate.query.factory_class为org.hibernate.hql.classic.ClassicQueryTranslatorFactory

2,直接在原基础上开发。

1、首先建立一个web工程,名字叫WebService,
2、把相应的axis2的jar文件考到WEB-INF的lib下
3、 在项目的WebRoot下的目录结构要和以前用war包是的目录结构一样(否则可能就要报 错了)
目录结构如图所示:

4、在src下建立package sample.service
5、建立提供服务的接口

Java代码
package sample.service;

/**
* 定义服务接口
* @author 11111
*
*/
public interface ServiceServer {
//定义服务方法
public String sayHello(String name);

}

package sample.service;

/**
* 定义服务接口
* @author 11111
*
*/
public interface ServiceServer {
//定义服务方法
public String sayHello(String name);

}

实现类:
Java代码
package sample.service;

public class ServiceServerImpl implements ServiceServer {

public String sayHello(String name) {

return "hello"+name;
}

}

package sample.service;

public class ServiceServerImpl implements ServiceServer {

public String sayHello(String name) {

return "hello"+name;
}

}

6、在src下建立applicationContext.xml文件
配置如下

Java代码
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">



<bean id="SayHelloService" class="sample.service.ServiceServerImpl">
</bean>


</beans>

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">


<bean id="SayHelloService" class="sample.service.ServiceServerImpl">
</bean>


</beans>
7、在WebRoor/WEB-INF/services/目录下建立目录sampleService(这个名字可以随便取)
然后建立在其下META-INF目录,然后再在其目录下建立services.xml
目录结构如下

services.xml的内容如下:

Java代码
<?xml version="1.0" encoding="UTF-8"?>


<service name="HelloWorld">
<description>web service</description>
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
</parameter>
<parameter name="SpringBeanName">SayHelloService</parameter>
//SpringBeanName名字是固定的不能改
//SayHelloService是spring中注册的实现类的id(这个大家肯定很清楚了)

<operation name="sayHello">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>

</service>

<?xml version="1.0" encoding="UTF-8"?>


<service name="HelloWorld">
<description>web service</description>
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
</parameter>
<parameter name="SpringBeanName">SayHelloService</parameter>
//SpringBeanName名字是固定的不能改
//SayHelloService是spring中注册的实现类的id(这个大家肯定很清楚了)

<operation name="sayHello">
<messageReceiver
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>

</service>
8、现在要配置一下web.xml了
内容如下:

Java代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>
<servlet-name>AxisServlet</servlet-name>
//注册axis2的servlet
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
//加载spring的配置文件
<context-param>
<param-name>contextConfigLocation</param-name>

<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
//增加spring监听器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet>
<servlet-name>AxisServlet</servlet-name>
//注册axis2的servlet
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
//加载spring的配置文件
<context-param>
<param-name>contextConfigLocation</param-name>

<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
//增加spring监听器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
9、启动tomcat 在浏览器中输入http://localhost:8080/WebService/services/listServices
可以看到一下内容说明我们的服务已经发布成功了

访问
http://localhost:8080/WebService/services/HelloWorld?wsdl
可以查看wsdl

待会就是访问我们的服务了(用axis2 的eclipse 插件自动生成客户端),
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值