我想结合Spring指南中的两个Spring(spring-boot)应用程序:
不幸的是,这些示例不能一起使用。servlet调度程序存在问题。添加dispatcherServlet bean之后-MVC Servlet无法正常工作(错误404)。
@Bean
public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
如何配置servlet调度程序以使其正常工作?
我想拥有:
localhost:8080/ws/*
- 网络服务localhost:8080/web/*
-MVC组件提前致谢!
问题在于的注册,MessageDispatcherServlet
因为dispatcherServlet
它覆盖了Spring Boot注册的名称DispatcherServlet
。网站的MVC部分需要后者。
要解决该问题,只需将您的方法重命名为除了dispatcherServlet
say之外的任何内容messageDispatcherServlet
。
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句