我目前正在开发一个web应用程序,该应用程序可以通过SOAP与Spring一起使用Spring5.1.3访问,并且不知道如何使用Java注册额外的servlet (在本例中是MessageDispatcherServlet for )。我应该注意,这是一个非引导应用程序。
我向官方的春季文档寻求帮助,但是本指南面向Spring (它使用的是ServletRegistrationBean,它是Spring专用的)。根据指南,MessageDispatcherServlet的注册方式如下:
@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, "/ws/*");
}
}除了ServletRegistrationBean驻留在我无法使用的org.springframework.boot.web.servlet => Spring Boot =>之外,这看起来很简单。如何在“非引导”标准Spring应用程序中注册我的MessageDispatherServlet?非常感谢你的提示和建议。
发布于 2019-07-18 08:00:13
谢谢各位的指点。我设法通过MessageDispatcherServlet注册了WebApplicationInitializer
public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(WebConfig.class);
container.addListener(new ContextLoaderListener(context));
// Message Dispatcher Servlet (SOAP)
MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
messageDispatcherServlet.setApplicationContext(context);
messageDispatcherServlet.setTransformWsdlLocations(true);
ServletRegistration.Dynamic messageDispatcher = container.addServlet("messageDispatcher", messageDispatcherServlet);
messageDispatcher.setLoadOnStartup(1);
messageDispatcher.addMapping("/ws/*");
}
}一旦你知道如何去做,你就会很简单:D
https://stackoverflow.com/questions/57060117
复制相似问题