首先maven导入jar包
引入文件信息
<properties>
<axis2.version>1.6.2</axis2.version>
</properties>
导入jar包
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-spring</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-xmlbeans</artifactId>
<version>${axis2.version}</version>
</dependency>
然后编写webservices的接口并写出实现类
public interface Test {
public int aa(int a,int b);
}
;
public class TestWSImpl implements TestWS{
public int aa(int a, int b) {
return a+b;
}
}
然后再applicationContext.xml注册bean
<bean id="applicationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
配置web.xml
这里注意,Struts2或者SpringMVC的拦截器不要设置为/,否则会被拦截
<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>
接着在WEB-INF下建立文件夹和xml
services/任意名字/META-INF/services.xml 注意这里是固定的,任意名字自己取
<?xml version="1.0" encoding="UTF-8" ?>
<service name="webservices的名字,可以随便取">
<description>
simple spring example
</description>
<parameter name="ServiceObjectSupplier">org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier</parameter>
<parameter name="SpringBeanName">你注册的bean名字</parameter>
<operation name="getValue">
<messageReceiver class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</operation>
</service>
然后运行项目就可以访问了,http://localhost:8080/My_SSM/services/webservices的名字?wsdl