Axis2+Spring简单实践
目录结构:
Axis2Demo
|--src
|--Axis2Server
|--TestServer.java
|--resources
|--appContext.xml
|--springmvc.xml
|--WebRoot
|--WEB-INF
|--services(固定名)
|--myservices(此名可随便)
|--META-INF(固定名)
|--services.xml(固定名)
|--web.xml
各个文件内容:
TestServer.java 服务具体逻辑实现类
import org.springframework.stereotype.Component;
/**
* @author yanzy
* @description
* @date 2018-03-14 13:46
* @created by intelliJ IDEA
*/
@Component(value = "https://www.it610.com/article/testServer")
public class TestServer {
public String greek(String greekWord){
System.out.print("hello World!");
return greekWord;
}
}
appContext.xml web.xml中通过contextConfigLocation指定的spring配置文件
springmvc.xml web.xml中通过
SpringMVC
org.springframework.web.servlet.DispatcherServlet
contextConfigLocationclasspath*:resources/springmvc.xml
1 SpringMVC
/rest/*
指定的springmvc配置文件
services.xml 将pojo发布为webservice的关键文件,此处配置为集成spring框架的配置
axis2 example
org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
testServer
web.xml web项目入口,配置Context内容与servlet、filter,特别注意axis2配置中拦截的地址不要使用
axis2/*
否则会出现异常
BlazeDS
BlazeDS Application
contextConfigLocationclasspath*:resources/appContext.xml
org.springframework.web.context.ContextLoaderListener
SpringMVC
org.springframework.web.servlet.DispatcherServlet
【Axis2+Spring简单实践】contextConfigLocationclasspath*:resources/springmvc.xml
1 SpringMVC
/rest/* AxisServlet
org.apache.axis2.transport.http.AxisServlet
1 AxisServlet
/services/*
因为本项目选用maven作为构建端,故将pom文件中关于axis2的内容也贴出来,若有jar包冲突请自行解决
1.6.2
org.apache.axis2
axis2
${axis2.version}
org.apache.axis2
axis2-spring
${axis2.version}
org.apache.axis2
axis2-adb
${axis2.version}
org.apache.axis2
axis2-kernel
${axis2.version}
org.apache.axis2
axis2-transport-http
${axis2.version}
org.apache.axis2
axis2-transport-local
${axis2.version}
org.apache.axis2
org.apache.axis2.osgi
${axis2.version}
org.apache.axis2
axis2-jaxws
${axis2.version}
至此,项目就可以部署到tomcat中观看效果了
打开浏览器,浏览如下地址:http://localhost:8080/TYDGPServer/services/mySoapService?wsdl
可以看到webservice的描述文档内容:
![Axis2+Spring简单实践](https://img.it610.com/image/info10/48fed7d18c09468ebde1ec4fac99a784.jpg)
文章图片
webservice信息描述文档 使用soapUI访问我们发出的webservice如下:
![Axis2+Spring简单实践](https://img.it610.com/image/info10/be965e51916046749024182f308d76c3.jpg)
文章图片
soapUI访问webservice 大功告成!!
ps:java调用webservice
public static void main(String[] args) throws Exception
{
//使用RPC方式调用WebService
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
//指定调用WebService的URL
EndpointReference targetEPR = new EndpointReference(
"http://localhost:8080/axis2/services/SimpleService");
options.setTo(targetEPR);
//指定getGreeting方法的参数值
Object[] opAddEntryArgs = new Object[] {"超人"};
//指定getGreeting方法返回值的数据类型的Class对象
Class[] classes = new Class[] {String.class};
//指定要调用的getGreeting方法及WSDL文件的命名空间
QName opAddEntry = new QName("http://ws.apache.org/axis2", "getGreeting");
//调用getGreeting方法并输出该方法的返回值
System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0]);
//下面是调用getPrice方法的代码,这些代码与调用getGreeting方法的代码类似
classes = new Class[] {int.class};
opAddEntry = new QName("http://ws.apache.org/axis2", "getPrice");
System.out.println(serviceClient.invokeBlocking(opAddEntry, new Object[]{}, classes)[0]);
}
推荐阅读
- 科学养胃,别被忽悠,其实真的很简单
- opencv|opencv C++模板匹配的简单实现
- 松软可口易消化,无需烤箱超简单,新手麻麻也能轻松成功~
- 不废话,代码实践带你掌握|不废话,代码实践带你掌握 强缓存、协商缓存!
- 六项精进20180530
- 简单心理2019春A期+32+张荣
- 《算法》-图[有向图]
- android防止连续点击的简单实现(kotlin)
- 机器学习一些简单笔记
- Android超简单实现沉浸式状态栏