我想学习spring-ws并从本教程开始: http://spring.io/guides/gs/producing-web-service/#initial。如何以编程方式配置MessageDispatcherServlet
我现在要做的是通过编程配置应用程序来启动非嵌入式servlet容器上的服务。
我被困在如何设置没有web.xml的消息分派器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(这是在教程示例工作)发送从来没有得到映射
我试过这个没有成功。对于RootContextConfiguration,我提供了WebServiceConfig类 - 就像教程中的一样,但没有ServletRegistrationBean。对于servletConfigClasses,我设置了CountryEndpoint - 即时猜测这是错误的? – John 2014-10-20 11:56:22
缺少上下文声明,应该是:\t \t AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); ? – John 2014-10-20 15:08:57
我应该注册DispatcherServlet还是MessageDispatcherServlet?我收到错误消息:没有按照您的建议使用DispatcherServlet为http请求找到映射 – John 2014-10-20 15:41:30