【发布时间】:2017-10-13 14:21:08
【问题描述】:
当我将我的 Spring Boot 应用程序作为 JAR 文件运行时,我的所有控制器都可以正常工作(尽管我仍然在日志中得到“没有找到...的处理程序方法”,但是以某种方式适当的控制器和视图呈现得很好。当我在 WAR 模式下运行它,它在日志中给我 404 和相同的错误“没有找到...的处理程序方法”。
这是我的应用程序类:
@SpringBootApplication
public class RAApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//set register error pagefilter false
//setRegisterErrorPageFilter(false);
return application.sources(RAApplication.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(RAApplication.class, args);
}
}
我的主要应用程序类在 com.xyz.abc 下,所有控制器都在 com.xyz.abc.controllers 下,其他所有组件都在 com.xyz.abc 的子包中。
/mappings 和 /beans 工作得很好,而 /mappings 确实显示了这样的内容:
"{[/],methods=[GET]}":{"bean":"requestMappingHandlerMapping","method":"public java.lang.String com.xyz.abc.controllers.HomeController.renderIndexPage(org.springframework.ui.Model)"}
仅供参考,我检查了只有一个 [/] 映射以防它有用。
任何可能出现问题的指针?所有通常的搜索都指向未找到控制器,但 /mappings 显示所有控制器均已正确映射,但为什么它在战争模式下给出 404 并在 jar 模式下出现错误?
谢谢!
更新:我已经设置
servlet.contextPath=/
在 application.properties 中,其他执行器端点也已正确配置,例如
15:21:09.253 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'metricsFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
15:21:09.254 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'webRequestLoggingFilter' to: [/*]
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Filter errorPageFilter was not registered (disabled)
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.FilterRegistrationBean - Mapping filter: 'applicationContextIdFilter' to: [/*]
15:21:09.255 [localhost-startStop-1] INFO org.springframework.boot.web.servlet.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/]
15:21:09.289 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.OrderedRequestContextFilter - Initializing filter 'requestContextFilter'
15:21:09.291 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.OrderedRequestContextFilter - Filter 'requestContextFilter' configured successfully
15:21:09.291 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.ApplicationContextHeaderFilter - Initializing filter 'applicationContextIdFilter'
15:21:09.291 [localhost-startStop-1] DEBUG org.springframework.boot.web.filter.ApplicationContextHeaderFilter - Filter 'applicationContextIdFilter' configured successfully
【问题讨论】:
-
您的 RabbitAssistApplication 和控制器在同一个包中吗?
-
控制器位于 Application 类所在的子包中。例如com.xyz.abc - 应用程序和 com.xyz.abc.controllers - 控制器
-
您是否能够看到类似以下 s.w.s.m.m.a.RequestMappingHandlerMapping 的任何日志:将“{[/]}”映射到所有端点的公共
-
@AmitKBist 不,我没有,这就是这个问题的原因。
-
从 maven 创建战争时,您是否将 spring-boot-starter-tomcat 依赖标记为提供?
标签: spring-mvc spring-boot spring-boot-actuator