文章目录
- 1. 引入依赖
- 2. Servlet
- 3.接口
- 4.实现类
- 5.配置工厂
- 6.启动类
- 7. server-config.wsdd
- 8. 访问
1. 引入依赖
<!--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 -->
2. Servlet
package com.example.demo;import org.apache.axis.transport.http.AxisServlet;@javax.servlet.annotation.WebServlet(urlPatterns = "/services/*",loadOnStartup = 1,name = "AxisServlet"
)
public class WebServlet extends AxisServlet {}
3.接口
package com.example.demo.service;public interface HelloService {public String sayHello(String info);
}
4.实现类
package com.example.demo.service.impl;import com.example.demo.service.HelloService;
import org.springframework.stereotype.Service;@Service
public class HelloServiceImpl implements HelloService {/*** http://localhost:8080/services/HelloServiceImpl?wsdl** @param info* @return*/@Overridepublic String sayHello(String info) {return "sayHello:" + info;}
}
5.配置工厂
直接复制即可
package com.example.demo;import org.apache.axis.AxisProperties;
import org.apache.axis.ConfigurationException;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.EngineConfigurationFactory;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.configuration.EngineConfigurationFactoryDefault;
import org.apache.axis.configuration.FileProvider;
import org.apache.axis.server.AxisServer;
import org.apache.axis.utils.ClassUtils;
import org.apache.axis.utils.Messages;
import org.apache.commons.logging.Log;import javax.servlet.ServletConfig;
import java.io.InputStream;public class EngineConfigurationFactoryServletextends EngineConfigurationFactoryDefault {protected static Log log =LogFactory.getLog(EngineConfigurationFactoryServlet.class.getName());private ServletConfig cfg;public static EngineConfigurationFactory newFactory(Object param) {return (param instanceof ServletConfig)? new EngineConfigurationFactoryServlet((ServletConfig) param): null;}protected EngineConfigurationFactoryServlet(ServletConfig conf) {super();this.cfg = conf;}public EngineConfiguration getServerEngineConfig() {return getServerEngineConfig(cfg);}private static EngineConfiguration getServerEngineConfig(ServletConfig cfg) {// Respect the system property setting for a different config fileString configFile = cfg.getInitParameter(OPTION_SERVER_CONFIG_FILE);if (configFile == null)configFile =AxisProperties.getProperty(OPTION_SERVER_CONFIG_FILE);if (configFile == null) {configFile = SERVER_CONFIG_FILE;}String appWebInfPath = "/WEB-INF";//由于部署方式变更为jar部署,此处不可以使用改方式获取路径
// ServletContext ctx = cfg.getServletContext();
// String realWebInfPath = ctx.getRealPath(appWebInfPath);FileProvider config = null;String realWebInfPath = EngineConfigurationFactoryServlet.class.getResource(appWebInfPath).getPath();InputStream iss = ClassUtils.getResourceAsStream(EngineConfigurationFactoryServlet.class, appWebInfPath + "/" + SERVER_CONFIG_FILE);if (iss != null) {config = new FileProvider(iss);}if (config == null) {log.error(Messages.getMessage("servletEngineWebInfError03", ""));}if (config == null && realWebInfPath != null) {try {config = new FileProvider(realWebInfPath, configFile);} catch (ConfigurationException e) {log.error(Messages.getMessage("servletEngineWebInfError00"), e);}}if (config == null) {log.warn(Messages.getMessage("servletEngineWebInfWarn00"));try {InputStream is =ClassUtils.getResourceAsStream(AxisServer.class,SERVER_CONFIG_FILE);config = new FileProvider(is);} catch (Exception e) {log.error(Messages.getMessage("servletEngineWebInfError02"), e);}}return config;}
}
6.启动类
package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;@SpringBootApplication
@ServletComponentScan //扫描自定义的WebFilter和WebListener,否则无法扫描到
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}
7. server-config.wsdd
创建webapp/WEB-INF目录
<?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="HelloServiceImpl" 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>
8. 访问
http://localhost:8080/services/HelloServiceImpl?wsdl