Spring Boot 项目启动日志
2017-09-26 14:23:08.443 INFO 3543 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@41fbdac4: startup date [Tue Sep 26 14:23:04 CST 2017]; root of context hierarchy 2017-09-26 14:23:08.529 INFO 3543 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/testboot/getuser]}" onto public com.aven.User com.aven.TestBootController.getUser() 2017-09-26 14:23:08.533 INFO 3543 --- [ main] 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) 2017-09-26 14:23:08.533 INFO 3543 --- [ main] 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,javax.servlet.http.HttpServletResponse) 2017-09-26 14:23:08.567 INFO 3543 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-09-26 14:23:08.567 INFO 3543 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-09-26 14:23:08.622 INFO 3543 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-09-26 14:23:08.807 INFO 3543 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2017-09-26 14:23:08.888 INFO 3543 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9090 (http) 2017-09-26 14:23:08.895 INFO 3543 --- [ main] com.Application : Started Application in 15.39 seconds (JVM running for 16.706) 2017-09-26 14:24:00.425 INFO 3543 --- [nio-9090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2017-09-26 14:24:00.425 INFO 3543 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2017-09-26 14:24:00.448 INFO 3543 --- [nio-9090-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 23 ms在 s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped 记录中就看不到对应的 Controller!
有的 Controller 可以 映射成功,有的却不行,这是什么原因呢?
其实这和 conflicts with existing, non-compatible bean definition of same name and class 的问题是一样的,
都是因为没有包名的原因。
2018-01-03更新
如果你访问的路径不对,也会报404的错误,
这里需要注意的一点是:如果你的项目是直接通过 main 函数启动的,那么 url 中就不带项目名!