[英]How to expose both a SOAP web-service and RESTful API at the same time in Spring Boot?
在Spring Boot 1.4.3中,我公开了一个可以在端口8080上成功运行的SOAP Web服务终结点。
为了运行状况检查,我还需要公开RESTful API。 我尝试同时使用Actuator和rest控制器:
@RestController
public class RESTapis {
@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/health")
public String healthCheck() {
return "ACK";
}
}
但在两种情况下,我都会得到相同的响应: HTTP 405(不允许使用方法) 。
如果禁用Web服务,REST api将返回HTTP 200。
怎样使SOAP Web服务和REST同时工作?
这是Web服务配置:
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/*");
}
}
因此,从messageDispatcherServlet方法开始,由于通配符注册,您似乎将servlet绑定到所有传入请求:
return new ServletRegistrationBean(servlet, "/*");
因此,MessageDispatcher拦截了所有传入请求,并尝试查找/ health并抛出http 405。
固定:
return new ServletRegistrationBean(servlet, "/soap-api/*");
说明:
通过将Message Dispatcher绑定到特定的URI名称空间,我们可以确保仅在/ soap-api / *名称空间上触发的所有请求都将被MessageDispatcher拦截。 并且所有其他请求都将被DispatcherServlet拦截,从而可以与Soap WS并行运行Rest接口。
建议:
不知道应用程序的原因/细节,但是不知道方法healthcheck()的名称,您可以查看使用Spring Boot执行器生成运行状况检查以及应用程序的指标。 您也可以覆盖它以进行自定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.