在类路径上检测到 2 个 Spring WebApplicationInitializers [英] 2 Spring WebApplicationInitializers detected on classpath
问题描述
我有一个 springboot webapp,当我在 tomcat 7.0.54 的服务器上部署它时,我在 catalina.out 中收到以下消息
i have a springboot webapp and when i deployed it on my server on tomcat 7.0.54 then i got following message in catalina.out
INFO: 2 Spring WebApplicationInitializers detected on classpath
并且我的应用程序正在部署两次导致异常
and my application is deploying twice which casue Exception
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [inbound] with key 'inbound'; nested exception is javax.management.InstanceAlreadyExistsException
但是我在本地系统上使用 tomcat 7.0.37 尝试了相同的 war 文件并且应用程序运行良好
but i tried the same war file on my local system with tomcat 7.0.37 and the application works fine
有什么建议吗?
谢谢.
推荐答案
我遇到了相同的情况.远程服务器上的 Spring Boot + Tomcat + InstanceAlreadyExistsException 但在我的本地 Tomcat 上运行良好.
I had an identical situation. Spring Boot + Tomcat + InstanceAlreadyExistsException on a remote server but worked perfectly on my local Tomcat.
原因是远程服务器在 server.xml 中有两个 Host 元素指向同一个 Tomcat appBase 目录 (webapps).这导致所有 webapps 被加载两次.对于某些 web 应用程序,这不是问题,但对于我来说,这是因为它尝试注册 MBean 两次.
The cause was the remote server having two Host elements in server.xml pointing to the same Tomcat appBase directory (webapps.) That caused all webapps to be loaded twice. For some webapps it wasn't a problem, but for mine it was because it tried to register MBeans twice.
我的解决方案是用另一个 Host 元素下的 Alias 替换一个 Host 元素.现在我只有一个 Host 元素,每个应用只加载一次.
My solution was to replace one of the Host elements with an Alias under the other Host element. Now I just have one Host element and apps are loaded only once each.
这篇关于在类路径上检测到 2 个 Spring WebApplicationInitializers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!