Springboot+Axis2+WebService(Springboot通过Axis2方式集成WebService)

1.导入maven依赖


	org.apache.axis2
	axis2-adb
	1.7.7


	org.apache.axis2
	axis2-transport-http
	1.7.7
	
		
			javax-servlet
			servlet-api
		
	


	org.apache.axis2
	axis2-transport-local
	1.7.7

2.服务接口

public class LoginService{
	public boolean login(String username, String password){
		boolean bool = false;
		if("admin".equals(username) && "123456".equals(password)){
			bool = true;
		}
		return bool;
	}
}

3.Axis2配置WebServiceConfig

import java.io.IOException;
import org.apache.axis2.transport.http.AxisServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.znv.wpu.common.utils.FileCopyUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @Axis2支持集成WebService配置
 * @通过解读XML进行配置(原因:Springboot通过Axis2集成Webservice违反了注解原理)
 * */
@Slf4j
@Configuration
public class WebServiceConfig {

	@Bean
	public ServletRegistrationBean axisServlet() {
		ServletRegistrationBean helloWorldServlet = new ServletRegistrationBean();
		helloWorldServlet.setServlet(new AxisServlet());// 这里的AxisServlet就是web.xml中的org.apache.axis2.transport.http.AxisServlet
		helloWorldServlet.addUrlMappings("/services/*");
		// 通过默认路径无法找到services.xml,这里需要指定一下路径,且必须是绝对路径
		String path = this.getClass().getResource("/ServicesPath").getPath().toString();
		if (path.toLowerCase().startsWith("file:")) {
			path = path.substring(5);
		}
		/**@如果获得到的地址里有感叹号,说明文件在压缩包(jar包)中,Axis2无法正常使用,需要拷贝到jar包外*/
		if (path.indexOf("!") != -1) {
			try {
				FileCopyUtils.copy("ServicesPath/services/MyWebService/META-INF/services.xml");
			} catch (IOException e) {
				e.printStackTrace();
			}
			path = path.substring(0, path.lastIndexOf("/", path.indexOf("!"))) + "/ServicesPath";
		}
		log.info("xml配置文件path={}","{"+path+"}");
		helloWorldServlet.addInitParameter("axis2.repository.path", path);
		helloWorldServlet.setLoadOnStartup(1);
		return helloWorldServlet;
	}
}

4.发布服务service.xml


	
		APP-WebServic  
	
	
		
		
	
	com.znv.android.LoginService


你可能感兴趣的:(Android,Java)