Search code examples
javaspringtomcat7spring-insight

Spring MVC 3.1 App: AbstractApplicationContext#refresh called multiple times during application startup


I have a REST web service built with Spring MVC, with annotation-based configuration and plus a web.xml in which org.springframework.web.context.support.AnnotationConfigWebApplicationContext is specified to be used.

During startup of the application in the log file I see some of the lines 3 times. (Hibernate initialization - SchemaUpdate, TableMetadata etc..., then configWebApplicationContext, then EhCacheManagerFactoryBean, then requestMappingHandlerMapping... and in this sequence 3 times).

The application starts with no errors and I can use the REST endpoints.

My concern is whether because of this my application will use more memory or cause some unpredicted behavior? Any insight is helpful.

Here's a screenshot of the application start-up captured by Spring Insight:

enter image description here


Solution

  • Ok, as I see, excerpt for the longer startup time, it actually doesn't use more memory, so that's good.

    As stated in the JavaDoc API, it loads or refreshes the persistent representation of the configuration.

    And @gigadot pointed good in the comment on the question, that I might have multiple dispatcher servlets, and I had two, WebInitializer implements WebApplicationInitializer in onStartup method, and one in web.xml in declaration. I removed the one in the web.xml, and now I had 2 calls to #refresh on startup instead of 3, and the memory consumption was the same.