2017-10-13 93 views
0

当我运行我的弹簧启动应用程序作为JAR文件时,所有我的控制器工作正常(虽然我仍然在日志中找到“没有找到处理程序方法...”,但不知何故适当的控制器和视图是。渲染得很好,当我在对战模式中运行它,它给了我404相同的错误日志中“没有发现......处理方法”春季启动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的子包中。

/映射和/豆的工作只是罚款和/映射确实显示是这样的:

"{[/],methods=[GET]}":{"bean":"requestMappingHandlerMapping","method":"public java.lang.String com.xyz.abc.controllers.HomeController.renderIndexPage(org.springframework.ui.Model)"} 

仅供参考,我查了一下,只有一个的[/]的情况下,这是非常有用的映射。

任何可能出错的指针?所有通常的搜索都指向没有找到控制器,但映射显示所有控制器映射正确,但为什么它会在战争模式下给出404并在jar模式下使用错误?

谢谢!

UPDATE:我已设置

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 
+0

是您的RabbitAssistApplication和控制器在同一个包中? –

+0

控制器位于Application类所在的子包中。例如com.xyz.abc - 应用程序和com.xyz.abc.controllers - 控制器 – magiclko

+0

您是否能够看到如下所示的任何日志swsmmaRequestMappingHandlerMapping:将“{[/]}”映射到您的所有终端的公共目录 –

回答

0

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

例如localhost:8080/in JAR模式在web容器中变为localhost:8080/myapp /。

+0

我已经在application.properties中设置了servlet.contextPath = /。忘了提及那个,更新了这个问题。抱歉! – magiclko

+0

但是你如何运行WAR? –