Spring boot 404仍然有效

时间:2017-10-13 14:21:09

标签: spring-mvc spring-boot spring-boot-actuator

当我将我的春季启动应用程序作为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)"}

仅供参考,我检查了[/]只有一个映射,以防它有用。

任何可能出错的指针?所有常见的搜索都指向未找到的控制器,但/映射显示所有这些都已正确映射,但为什么它在war模式下给出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

1 个答案:

答案 0 :(得分:0)

如果在像Tomcat这样的Web容器中部署WAR,那么您将拥有上下文路径。

例如,localhost:8080 /在JAR模式下变为localhost:8080 / myapp /在Web容器中。