新建一个CustomMessageDispatcherServlet类,以扩展以下MessageDispatcherServlet类,
java
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import javax.servlet.http.HttpServletRequest;
public class CustomMessageDispatcherServlet extends MessageDispatcherServlet {
@Override
protected String transformWsdlLocation(HttpServletRequest request, String wsdlLocation) {
String requestUri = request.getRequestURI();
if (requestUri.contains("/WebservicesConnector/services/countries")) {
return "countries.wsdl";
} else if (requestUri.contains("/FinancingService/FinancingUpdate.asmx")) {
return "kinsai.wsdl";
}
return super.transformWsdlLocation(request, wsdlLocation);
}
}
そして、messageDispatcherServlet
メソッド内で、新しいカスタムのMessageDispatcherServlet
を設定します。
java
@Bean
public ServletRegistrationBean<CustomMessageDispatcherServlet> messageDispatcherServlet() {
CustomMessageDispatcherServlet servlet = new CustomMessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}