【发布时间】:2014-12-15 09:25:56
【问题描述】:
我正在尝试学习 spring-ws 并从本教程开始: http://spring.io/guides/gs/producing-web-service/#initial.
我现在想做的是通过以编程方式配置应用程序,在非嵌入式 servlet 容器上启动服务。
我不知道如何在没有 web.xml 的情况下设置 Message Dispatcher Servlet。我试图做的是 实现WebApplicationInitializer接口的onStartup(ServletContext servletContext)方法。
public class ServerInitializer implements WebApplicationInitializer{
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(WebServiceConfig.class.getName());
servletContext.addListener(new ContextLoaderListener(context));
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(context);
servlet.setTransformWsdlLocations(true);
// Create dispatcher for named context
ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("DispatcherServlet", servlet);
// Load on startup
dispatcherServlet.setLoadOnStartup(1);
// Add URL mapping for dispatcher
dispatcherServlet.addMapping("/*");
}
}
但是,当我将它部署到 tomcat 时,我使用 SOAP UI(正在处理教程示例)发送的请求永远不会被映射
【问题讨论】:
标签: java spring tomcat servlets