Spring Boot devtools控制器映射不会重新加载

时间:2015-09-22 18:10:12

标签: spring intellij-idea spring-boot

我在使用 spring-boot-devtools 时遇到问题,当应用程序启动时,spring boot会加载控制器中定义的所有映射。

2015-09-22 21:11:17.752  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f18fa2d: startup date [Tue Sep 22 21:11:02 PKT 2015]; root of context hierarchy
2015-09-22 21:11:17.942  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/properties]}" onto java.util.Properties com.sample.web.HomeController.properties()
2015-09-22 21:11:17.946  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto java.lang.String com.sample.web.HomeController.index()
2015-09-22 21:11:17.947  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/employee]}" onto public java.util.List<com.sample.domain.Employee> com.sample.web.HomeController.getEmployee()
2015-09-22 21:11:17.957  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-09-22 21:11:17.957  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)

但是当在控制器中进行一些更改并使用CTRL + F9在Intellij IDEA中构建时,spring-boot-devtools会启动并重新加载类,但它不会再次加载控制器映射。

2015-09-22 21:11:53.492  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@54e74c05: startup date [Tue Sep 22 21:11:45 PKT 2015]; root of context hierarchy
2015-09-22 21:11:53.549  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-09-22 21:11:53.550  INFO 1880 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2015-09-22 21:11:53.639  INFO 1880 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

在内容显示后访问应用程序时

  

Whitelabel错误页面

     

此应用程序没有/ error的显式映射,因此您将此视为后备。

     

Tue Sep 22 21:14:11 PKT 2015   出现意外错误(type = Not Found,status = 404)。   没有可用的消息

1 个答案:

答案 0 :(得分:1)

我偶然发现了同样的问题。添加thymeleaf配置类为我解决了它。

类似的东西:

@Configuration
public class ThymeleafConfiguration {
    @Bean
    public ITemplateResolver defaultTemplateResolver() {
        TemplateResolver resolver = new FileTemplateResolver();
        resolver.setSuffix(".html");            
        resolver.setPrefix("/home/.../IdeaProjects/.../src/main/resources/templates/" );
        resolver.setTemplateMode("HTML5");
        resolver.setCharacterEncoding("UTF-8");
        resolver.setCacheable(false);
        return resolver;
    }
}