本文亲测;
1、从官网下载axis2相关api,地址是:http://axis.apache.org/axis2/java/core/download.html,我下载的是axis2-1.7.6-bin;
2、从axis2-1.7.6-bin里面找到webapp,WEB-INF,将conf,modules,service全部复制到项目下,如下图:
复制到WEB-INF下面(axis2-1.7.6-bin里面有);
3、在项目web.xml中加入axis2支持:
<!-- 加入Axis2支持 -->
<servlet>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
4、接口发布java代码
package cn.yql8.sappi.service; import java.io.Serializable;
import java.util.List;
/**
* <!-- 公司代码主数据 -->
* @author Administrator
*
*/
public class Companycode {
public String getCompanycode(List<Masterdatas> list)throws Exception{
System.out.println("-----------------------------");
return "1";
} public static class Masterdatas implements Serializable{ /**
*
*/
private static final long serialVersionUID = 1L;
String MANDT; //客户端 主键
String BUKRS; //公司代码 主键
String BUTXT; //公司名称 主键
String LAND1; //国家代码 主键
String ORT01; //城市
String WAERS; //货币码
String SPRAS; //语言代码
String KTOPL; //帐目表
String ADRNR; //地址
public String getMANDT() {
return MANDT;
}
public void setMANDT(String mANDT) {
MANDT = mANDT;
}
public String getBUKRS() {
return BUKRS;
}
public void setBUKRS(String bUKRS) {
BUKRS = bUKRS;
}
public String getBUTXT() {
return BUTXT;
}
public void setBUTXT(String bUTXT) {
BUTXT = bUTXT;
}
public String getLAND1() {
return LAND1;
}
public void setLAND1(String lAND1) {
LAND1 = lAND1;
}
public String getORT01() {
return ORT01;
}
public void setORT01(String oRT01) {
ORT01 = oRT01;
}
public String getWAERS() {
return WAERS;
}
public void setWAERS(String wAERS) {
WAERS = wAERS;
}
public String getSPRAS() {
return SPRAS;
}
public void setSPRAS(String sPRAS) {
SPRAS = sPRAS;
}
public String getKTOPL() {
return KTOPL;
}
public void setKTOPL(String kTOPL) {
KTOPL = kTOPL;
}
public String getADRNR() {
return ADRNR;
}
public void setADRNR(String aDRNR) {
ADRNR = aDRNR;
} }
}
5、springmvc.xml中注入AXIS2支持
<bean id="applicationContext" class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />
6、pom.xml引入的对应的jar包
<!-- axis2.jar -->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb-codegen</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-clustering</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-codegen</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-corba</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-fastinfoset</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-java2wsdl</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxbri</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jibx</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-json</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-metadata</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-mtompolicy</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-saaj</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-soapmonitor-servlet</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-spring</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>${axis-version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-xmlbeans</artifactId>
<version>${axis-version}</version>
</dependency>
7、services.xml中发布接口
<serviceGroup>
<service name="companycodeService" >
<description>
Test Companycode Example
</description>
<!-- 公司代码主数据 -->
<parameter name="ServiceClass">cn.yql8.sappi.service.Companycode</parameter>
<!-- <parameter name="SpringBeanName">emptyBoxService</parameter> -->
<!-- 公司代码主数据 -->
<operation name="getCompanycode">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<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>
</serviceGroup>
8、浏览器地址访问:
http://localhost:8080/cgxtpt/services/CompanycodeService?wsdl
9、可以用SOAPUI进行测试;