1. 创建spring boot项目
2. 引入axis1.4依赖
<!--axis start -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<!--axis end -->
3. 创建service
3.1 创建服务接口
package com.example.demo.service;
public interface HelloService {
String sayHello(String info);
}
3.2 创建接口实现类?
package com.example.demo.service.impl;
import com.example.demo.service.HelloService;
import org.springframework.stereotype.Service;
@Service
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String info) {
return "远程回复:" + info;
}
}
3.3 创建webapp/WEB-INF/server-config.wsdd
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<handler type="java:org.apache.axis.handlers.http.URLMapper"
name="URLMapper" />
<!--要告诉别人的接口名-->
<service name="MyHelloService" provider="java:RPC">
<!--这个是 实现类-->
<parameter name="className" value="com.example.demo.service.impl.HelloServiceImpl" />
<!--这是是暴露的方法名 比如可以值暴露一个-->
<parameter name="allowedMethods" value="sayHello" />
<!--这是是暴露的方法名 也可以用* 表示暴露全部的public方法-->
<!--<parameter name="allowedMethods" value="*" />-->
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
</requestFlow>
</transport>
</deployment>
3.4 创建WebServlet
package com.example.demo.config;
import org.apache.axis.transport.http.AxisServlet;
@javax.servlet.annotation.WebServlet(
urlPatterns = "/services/*",
loadOnStartup = 1,
name = "AxisServlet"
)
public class WebServlet extends AxisServlet {
}
3.5 修改spring boot启动类,添加注解
@ServletComponentScan //扫描自定义的WebFilter和WebListener,否则无法扫描到
此时访问http://localhost:8080/services/MyHelloService?wsdl http://localhost:8080/services/MyHelloService?wsdl可以看到如下界面

?4?创建客户端
4.1 下载安装
https://mirrors.tuna.tsinghua.edu.cn/apache/axis/axis/java/1.4/

下载其中一个,解压
4.2 创建client
打开cmd,进入axis解压目录
java -Djava.ext.dirs=lib/ org.apache.axis.wsdl.WSDL2Java http://localhost:8080/services/MyHelloService?wsdl -p com.example.demo.client
?执行结束后会出现以下内容

4.3 将文件拷贝到项目中
?4.4 创建客户端代码
package com.example.demo.client;
import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
public class HelloServiceClient {
public static void main(String[] args) {
HelloServiceImplServiceLocator helloServiceImplServiceLocator = new HelloServiceImplServiceLocator();
try {
HelloServiceImpl helloService = helloServiceImplServiceLocator.getMyHelloService();
System.out.println(helloService.sayHello("你好"));
} catch (ServiceException | RemoteException e) {
e.printStackTrace();
}
}
}
4.5 测试客户端

?
|