0
votes

when I deploy a new version (3.0.1) of my webapp on Tomcat 8 [on tomcat is deployed an older version (3.0.0)] i get this exception:

Failed to register LiveBeansView MBean; nested exception is javax.management.InstanceAlreadyExistsException

org.springframework.context.ApplicationContextException: Failed to register LiveBeansView MBean; nested exception is javax.management.InstanceAlreadyExistsException: security-base,security-api:application=/MyWebApplication at org.springframework.context.support.LiveBeansView.registerApplicationContext(LiveBeansView.java:72) at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:776) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4727) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:473) at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1617) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1483) at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:731) at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:424) at javax.servlet.http.HttpServlet.service(HttpServlet.java:651) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:589) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: javax.management.InstanceAlreadyExistsException: security-base,security-api:application=/MyWebApplication 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.context.support.LiveBeansView.registerApplicationContext(LiveBeansView.java:68) ... 51 more

In web.xml of my application i have this configuration:

<context-param>  
    <param-name>spring.profiles.active</param-name>  
    <param-value>security-base,security-api</param-value>  
</context-param>  
<context-param>  
    <param-name>spring.profiles.default</param-name>  
    <param-value>security-base,security-api</param-value>  
</context-param>
<context-param>  
    <param-name>spring.liveBeansView.mbeanDomain</param-name>  
    <param-value>security-base,security-api</param-value>  
</context-param>

Anyone can help me ?

2

2 Answers

2
votes

Since you have two deployments on your Tomcat server for the same application (albeit different versions), you'll need to name your MBeans differently. Since MBeans are accessed per server (via a single JMX endpoint), each MBean identifier has to be separate.

You have a few options to make these unique in your apps:

  1. The simplest solution is to set endpoints.jmx.unique-names to true and let Spring Boot make the MBean paths unique for you, rather than using default names. .
  2. Alternatively, you can change the MBean domain by setting thespring.jmx.default-domain=applicationname for the application
  3. And you might likely not need this, but adding here for completeness; if you're manually loading your beans in Spring Configuration, you can add the EnableMBeanExport specifying a domain as such:

    @Configuration
    @EnableMBeanExport(defaultDomain="first")
    public class MBeanConfig {...}
    
0
votes

In my application 'spring.profiles' were added to get rid of debug log. spring jndi NamingException: Name [spring.liveBeansView.mbeanDomain] is not bound in this Context I fixed this issue by modifying web.xml for each deployed application making param-value unique per web.xml.

<param-value>prod</param-value>

vs

<param-value>test</param-value>

For example:

Production:

  <context-param>  
    <param-name>spring.profiles.active</param-name>  
    <param-value>prod</param-value>  
  </context-param>  
  <context-param>  
    <param-name>spring.profiles.default</param-name>  
    <param-value>prod</param-value>  
  </context-param>
  <context-param>  
    <param-name>spring.liveBeansView.mbeanDomain</param-name>  
    <param-value>prod</param-value>  
  </context-param>

Testing

  <context-param>  
    <param-name>spring.profiles.active</param-name>  
    <param-value>test</param-value>  
  </context-param>  
  <context-param>  
    <param-name>spring.profiles.default</param-name>  
    <param-value>test</param-value>  
  </context-param>
  <context-param>  
    <param-name>spring.liveBeansView.mbeanDomain</param-name>  
    <param-value>test</param-value>  
  </context-param>