Tomcat reports error when publishing war: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardCo

Question

  • Java8 code has been developed with IDEA before. The Tomcat that comes with IDEA runs without problems, and it runs with my local Tomcat without problems. However, when deployed to a remote server, the following error is reported.

Tomcat reports the following error:

Tomcat error: 05-Sep-2023 17:14:54.249 SEVERE [localhost-startStop-8] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
        org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/three2]]
                at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:727)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
                at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1016)
                at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
                at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
                at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
                at java.lang.Thread.run(Thread.java:750)
        Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.cloud.context.environment.EnvironmentManager@77298a91] with key 'environmentManager'; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework .cloud.context.environment:name=environmentManager,type=EnvironmentManager
                at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:628)
                at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:550)
                at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:432)
                at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781)
                at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
                at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
                at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
                at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
                at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
                at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
                at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
                at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
                at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
                at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221)
                at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
                ... 10 more
        Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager
                at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
                at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
                at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
                at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195)
                at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:683)
                at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:618)
                ... 25 more

Troubleshooting

  • Through the phenomenon (both IDEA and Tomcat in local windows can run), it is certain that it is not a code problem, then it must be a Tomcat problem.
  • It is located that it is a problem with Tomcat. So where is the problem with Tomcat? It must be a configuration problem.
  • According to the error reason: Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [org.springframework.cloud.context.environment.EnvironmentManager@77298a91] with key ‘environmentManager’;
    • When I first saw this error, I thought it was a failure to register the MBean object. This showed that it should be a code problem, but the code problem has been ruled out before, so there must be a problem when Tomcat is loading.
    • The problem is located when Tomcat is loaded, then it is most likely a problem of jar dependency when Tomcat is loaded.
    • Since it is a problem of “class loading settings, scanning classes”, the configuration file responsible for configuring Tomcat is catalina.properties. At this point, the problem has been clearly identified.

Resolution process

  1. Modify the configuration class: Open catalina.properties and modify the scanning configuration. tomcat.util.scan.StandardJarScanFilter.jarsToSkip represents the jar package that needs to be skipped when starting Tomcat. Configure here\,*,
  2. Close Tomcat
  3. Delete the relevant decompressed cache in the webapps folder
  4. Start Tomcat
  5. Check the startup log of Tomcat and find that no error is reported. The backend interface can be accessed through the url. The problem is solved.