making / hajiboot-samples

書籍「はじめてのSpring Boot」のサポートページ
133 stars 67 forks source link

[質問] DispatcherServletの初期化タイミングについて #8

Open kazuki43zoo opened 9 years ago

kazuki43zoo commented 9 years ago

デフォルトだと、初回アクセス時に初期化が実行されているようにみえますが、サーバ起動時に初期化したい場合はどのようにすればいいのでしょうか?

起動時のログ

...
2014-11-24 21:20:47.866  INFO 95074 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-11-24 21:20:47.953  INFO 95074 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2014-11-24 21:20:47.956  INFO 95074 --- [           main] com.example.App                          : Started App in 3.695 seconds (JVM running for 4.161)

初回アクセス時に出力されるログ

2014-11-24 21:21:20.431  INFO 95074 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2014-11-24 21:21:20.431  INFO 95074 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2014-11-24 21:21:20.445  INFO 95074 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 13 ms
kazuki43zoo commented 9 years ago

あ、でも

2014-11-24 21:37:05.273  INFO 95198 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-11-24 21:37:05.459  INFO 95198 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto java.lang.String com.example.App.home()
2014-11-24 21:37:05.461  INFO 95198 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" 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)
2014-11-24 21:37:05.462  INFO 95198 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2014-11-24 21:37:05.488  INFO 95198 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-11-24 21:37:05.489  INFO 95198 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

というログがでているから、実際の初期化はされてるのかな?