简体   繁体   English

Spring MVC 3.1应用程序:AbstractApplicationContext#refresh在应用程序启动期间多次调用

[英]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. 我有一个使用Spring MVC构建的REST Web服务,具有基于注释的配置,还有一个web.xml,其中指定使用org.springframework.web.context.support.AnnotationConfigWebApplicationContext

During startup of the application in the log file I see some of the lines 3 times. 在日志文件中启动应用程序期间,我看到了3行其中的一些内容。 (Hibernate initialization - SchemaUpdate , TableMetadata etc..., then configWebApplicationContext , then EhCacheManagerFactoryBean , then requestMappingHandlerMapping ... and in this sequence 3 times). (休眠初始化- SchemaUpdateTableMetadata等等,然后configWebApplicationContext ,然后EhCacheManagerFactoryBean ,然后requestMappingHandlerMapping ...在这个序列的3倍)。

The application starts with no errors and I can use the REST endpoints. 该应用程序启动时没有错误,我可以使用REST端点。

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: 这是Spring Insight捕获的应用程序启动的屏幕截图:

在此处输入图片说明

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. JavaDoc API中所述,它加载或刷新配置的持久表示。

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. @gigadot 在对该问题评论中指出很好,我可能有多个调度程序servlet,而我有两个, WebInitializer implements WebApplicationInitializer在onStartup方法中WebInitializer implements WebApplicationInitializer ,一个在web.xml中的声明中。 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. 我在web.xml中删除了一个,现在在启动时有2个调用#refresh调用,而不是3个,并且内存消耗是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM