axis2+spring集成
1、新建一个web project项目,最终工程目录如下:
注意:本文只注重webservice服务器端的开发,因此com.ljq.client和com.ljq.test忽略不计
2、添加所需jar
3、接口HelloWorld
package com.ljq.service;
publicinterface HelloWorld {
public String greeting(String name);
public String print();
}
publicinterface HelloWorld {
public String greeting(String name);
public String print();
}
4、接口实现类HelloWorldBean
package com.ljq.service;
publicclass HelloWorldBean implements HelloWorld {
public String greeting(String name) {
return"你好 "+name;
}
public String print() {
return"我叫林计钦";
}
}
publicclass HelloWorldBean implements HelloWorld {
public String greeting(String name) {
return"你好 "+name;
}
public String print() {
return"我叫林计钦";
}
}
5、webservice类HelloWorldWebService
package com.ljq.service;
import org.apache.axis2.AxisFault;
import org.apache.axis2.ServiceObjectSupplier;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.i18n.Messages;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* 可能出现Axis2 spring bean not found 或者 Spring applicationContext not found。
*
* 解决办法:构建自己的ServiceObjectSupplier,实现接口ServiceObjectSupplier,同时也实现Spring的ApplicationContextAware接口
*
*
* @author Administrator
*
*/
publicclass HelloWorldWebService implements ServiceObjectSupplier,
ApplicationContextAware {
privatestatic ApplicationContext ctx;
public Object getServiceObject(AxisService axisService) throws AxisFault {
Parameter springBeanName = axisService.getParameter("SpringBeanName");
String beanName = ((String) springBeanName.getValue()).trim();
if (beanName !=null) {
if (ctx ==null)
thrownew AxisFault("applicationContext is NULL! ");
if (ctx.getBean(beanName) ==null)
thrownew AxisFault("Axis2 Can't find Spring Bean: "+ beanName);
return ctx.getBean(beanName);
} else {
thrownew AxisFault(Messages.getMessage("paramIsNotSpecified",
"SERVICE_SPRING_BEANNAME"));
}
}
publicvoid setApplicationContext(ApplicationContext ctx)
throws BeansException {
this.ctx = ctx;
}
}
import org.apache.axis2.AxisFault;
import org.apache.axis2.ServiceObjectSupplier;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.i18n.Messages;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* 可能出现Axis2 spring bean not found 或者 Spring applicationContext not found。
*
* 解决办法:构建自己的ServiceObjectSupplier,实现接口ServiceObjectSupplier,同时也实现Spring的ApplicationContextAware接口
*
*
* @author Administrator
*
*/
publicclass HelloWorldWebService implements ServiceObjectSupplier,
ApplicationContextAware {
privatestatic ApplicationContext ctx;
public Object getServiceObject(AxisService axisService) throws AxisFault {
Parameter springBeanName = axisService.getParameter("SpringBeanName");
String beanName = ((String) springBeanName.getValue()).trim();
if (beanName !=null) {
if (ctx ==null)
thrownew AxisFault("applicationContext is NULL! ");
if (ctx.getBean(beanName) ==null)
thrownew AxisFault("Axis2 Can't find Spring Bean: "+ beanName);
return ctx.getBean(beanName);
} else {
thrownew AxisFault(Messages.getMessage("paramIsNotSpecified",
"SERVICE_SPRING_BEANNAME"));
}
}
publicvoid setApplicationContext(ApplicationContext ctx)
throws BeansException {
this.ctx = ctx;
}
}
6、配置web.xml文件
<?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">
<!-- 添加spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 加载spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 注册axis2的servlet -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<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">
<!-- 添加spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 加载spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- 注册axis2的servlet -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
7、在WEB-INF目录下配置applicationContext.xml(不存在则自己创建)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="applicationContext"
class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"/>
<bean id="helloWorld" class="com.ljq.service.HelloWorldBean"></bean>
</beans>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="applicationContext"
class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder"/>
<bean id="helloWorld" class="com.ljq.service.HelloWorldBean"></bean>
</beans>
8、在WEB-INF\services\axis\META-INF\目录下配置services.xml(不存在则自己创建)
<?xml version="1.0" encoding="UTF-8"?>
<service name="hwWebService">
<description>axis2与spring集成案例</description>
<!-- 通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象 -->
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter>
<!--
SpringBeanName固定的不能改
helloWorld是spring中注册的实现类得id
-->
<parameter name="SpringBeanName">helloWorld</parameter>
<!--
在这里最值得注意的是<messageReceivers>元素,该元素用于设置处理WebService方法的处理器。
例如,getGreeting方法有一个返回值,因此,需要使用可处理输入输出的RPCMessageReceiver类,
而update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。
-->
<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>
<service name="hwWebService">
<description>axis2与spring集成案例</description>
<!-- 通过ServiceObjectSupplier参数指定SpringServletContextObjectSupplier类来获得Spring的ApplicationContext对象 -->
<parameter name="ServiceObjectSupplier">
org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier
</parameter>
<!--
SpringBeanName固定的不能改
helloWorld是spring中注册的实现类得id
-->
<parameter name="SpringBeanName">helloWorld</parameter>
<!--
在这里最值得注意的是<messageReceivers>元素,该元素用于设置处理WebService方法的处理器。
例如,getGreeting方法有一个返回值,因此,需要使用可处理输入输出的RPCMessageReceiver类,
而update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。
-->
<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>
axis2+spring集成到此已经开发完成,接下把工程部署到tomcat,
然后通过http://localhost:8083/axis2spring/services/hwWebService?wsdl访问
相关推荐
axis2+spring+ibatis整合的一个项目,含webservice文件传输
axis1.4+mybatis3+spring3集成实现webservice;websphere下Log4j记录日志解决方案;
axis2与spring的集成,在application中配置要发布的Java类,然后配置aar文件,在aar打包文件中的services.xml要嵌入 <parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers....
spring+axis集成webservice
springboot集成axis2-1.7.9部署和调用实例
Axis2集成Spring发布WebServices服务
Spring集成AXIS2的Web_service配置方法
通过axis2与spring进行集成,发布webservice服务,
本示例是在 Axis2 通过 外部 Spring容器 获取指定的实现Bean,以提供服务。全部自己写WSDL和服务实现类,不使用 Axis2提供的 Java2WSDL 和 WSDL2Java 工具
spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码
Spring集成axis2实现webservice所用到的Jar包,将所有的包放到项目的LIB目录下面
主流的spring4mvc+Mybatis,并整合了axis2实现webservice接口开发。利用quartz注解实现任务作业功能源码。利用spring RoutingDataSource实现动态数据源切换
NULL 博文链接:https://8324.iteye.com/blog/668274
NULL 博文链接:https://wujianjun.iteye.com/blog/517152
使用axis2与spring3进行集成,实现的webservice服务。 资料为myeclipse下的web工程,可解压后直接导入。 发布到tomcat6下运行。
axis1.4 spring3.0 集成 实现 web service 服务端, axis1.4 客户端认证,授权,访问日志记录,集成spring 解决 PHP 调用web service 无法认证,和解析soap 模板
包含集成文档,所需jar包,测试类,已用于实际项目开发
相对于Axis来说,目前XFire相对受欢迎,加上其提供了和Spring集成的支持,在目前的Web Service开源社区拥有众多的追随者。并且因为XFire为Spring提供的支持,使得我们可以很容易在Spring中使用XFire构建Web Service...
webserice开发工具。Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持Spring、JSON等技术。
Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持Spring、JSON等技术