2014-02-23

Spring mvc framework context loaded twice??

Context

I have developed the simple scheduler (task timer) application using spring framework with mvc.
Application only log "Hello!!" string every 10 seconds.

Code example

spring-servlet.xml:



web.xml:






Surprisingly in logs I've noticed double logs with hello string?? WTF?

Looking into context start logs

2014-02-23T23:18:08|INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring root WebApplicationContext
2014-02-23T23:18:08|INFO: Root WebApplicationContext: initialization started
2014-02-23T23:18:08|INFO: Refreshing Root WebApplicationContext: startup date [Sun Feb 23 23:18:08 CET 2014]; root of context hierarchy
2014-02-23T23:18:09|INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/springmvc-servlet.xml]
2014-02-23T23:18:09|INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2014-02-23T23:18:09|INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@88fb55: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,runScheduler,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.context.annotation.internalScheduledAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
2014-02-23T23:18:09|INFO: Hello!!
2014-02-23T23:18:09|INFO: Root WebApplicationContext: initialization completed in 838 ms
2014-02-23T23:18:09|INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'springmvc'
2014-02-23T23:18:09|INFO: FrameworkServlet 'springmvc': initialization started
2014-02-23T23:18:09|INFO: Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Sun Feb 23 23:18:09 CET 2014]; parent: Root WebApplicationContext
2014-02-23T23:18:09.590+0100|INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/springmvc-servlet.xml]
2014-02-23T23:18:09|INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2014-02-23T23:18:09|INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3d2bac: defining beans [helloController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,runScheduler,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.internalAsyncAnnotationProcessor,org.springframework.context.annotation.internalScheduledAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@88fb55
2014-02-23T23:18:09|INFO: Mapped URL path [/welcome] onto handler 'helloController'
2014-02-23T23:18:09|INFO: Mapped URL path [/welcome.*] onto handler 'helloController'
2014-02-23T23:18:09|INFO: Mapped URL path [/welcome/] onto handler 'helloController'
2014-02-23T23:18:09|INFO: Hello!!
2014-02-23T23:18:09|INFO: FrameworkServlet 'springmvc': initialization completed in 383 ms

 Solution

Context was loaded twice from /WEB-INF/springmvc-servlet.xml config file.  
contextConfigLocation is uncorrectly invoke. It should point on spring application context definition (different than servlet definition - springmvc-servlet.xml).
Changing to other applicationConfig.xml should help fix the problem:


Brak komentarzy:

Prześlij komentarz