webservices系列(六)——spring整合Axis2
来源:互联网 发布:java pdf生成 编辑:程序博客网 时间:2024/06/05 12:42
1.新建一个动态网站项目webservice_test4,最终工程目录如下
2.准备这些jar包
3.在web.xml中配置spring和axis
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>webservice_test4</display-name> <!-- 添加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>4.webservice实现代码
HelloWorld.java
public interface HelloWorld {public String greeting(String name);public String print();}HelloWorldImpl.javapublic class HelloWorldImpl implements HelloWorld{public String greeting(String name) {return "hello " + name;}public String print() {return "print";}}HelloWorldService.java
public class HelloWorldService implements ServiceObjectSupplier, ApplicationContextAware{private ApplicationContext ctx;public void setApplicationContext(ApplicationContext arg0) throws BeansException {ctx = arg0;}@Overridepublic Object getServiceObject(AxisService arg0) throws AxisFault {Parameter springBeanName = arg0.getParameter("SpringBeanName");String beanName = ((String)springBeanName.getValue()).trim();if(beanName != null) {if(ctx == null) {throw new AxisFault("ApplicationContext is null");}if(ctx.getBean(beanName) == null) {throw new AxisFault("axis2 can't find Spring Bean :" + beanName);}return ctx.getBean(beanName);} else {throw new AxisFault(Messages.getMessage("paramIsNotSpecified", "SERVICE_SPRING_BEANNAME"));}}}5.axis2的接口配置文件services.xml
<?xml version="1.0" encoding="UTF-8"?><service name="hwWebService"><description>axis2与spring集成</description><parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter><parameter name="SpringBeanName">helloWorld</parameter><messageReceiver><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" /></messageReceiver></service>6.spring的配置文件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="applictationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" /><bean id="helloWorld" class="com.lc.service.HelloWorldImpl"></bean></beans>发布到tomcat上,打开链接http://localhost:8080/webservice_test4/services/hwWebService?wsdl
参考资料
[1].spring和axis2整合:http://www.cnblogs.com/yuxuan/p/4028359.html
0 0
- webservices系列(六)——spring整合Axis2
- webservices系列(五)——javaweb整合Axis2及多service配置
- webservices系列(四)——Axis2入门框架
- axis2 spring集成开发webServices
- axis2 webservices+Spring Quartz+IO
- webservices spring 整合
- Spring学习——(六)Spring与Hibernate整合
- springboot系列教程(六)——整合jdbctemplate
- axis2整合spring
- Axis2整合Spring AOP
- Axis2整合spring
- axis2 和spring整合
- webservice axis2+spring整合
- Axis2+spring整合实例
- Axis2+spring整合实例
- spring系列(六):SSH整合一
- Spring Boot干货——(六)SpringBoot整合mybatis
- webservices系列(二)——JAX-WS文件上传下载
- 题目1146:Flipping Pancake
- 在MyEclipse中上传项目到github的步骤(很详细)
- 数据结构(1):线性表
- 【寒江雪】测试环境
- synchronized
- webservices系列(六)——spring整合Axis2
- [资源] 开发笔记
- 《收获,不止Oracle》读书笔记(二):表连接
- 大数据学习——HBase 入门
- LeetCode079 Word Search
- 设计模式——代理模式
- lammps 编译安装测试说明 (提供免费测试)
- 4.19
- LeetCode080 Remove Duplicates from Sorted Array II