Cannot integrate JMX with Spring application

后端 未结 2 1752
悲&欢浪女
悲&欢浪女 2021-01-07 04:11

I have got a SPRING application. When I run

mvn jetty:run

everything is ok.

I would like to use JMX

相关标签:
2条回答
  • 2021-01-07 04:43

    This is happening as the bean is trying to initialize even after its initialized once.

    I was facing the same issue with RabbitMQ configuration in Spring TestNG testcases.

    Use @DirtiesContext as a class level annotation for every testcase class.

    This will create applicationcontext and kill it once the testcase class is run and a new applicationcontext will be created for the next testcase class.

    Example -

    @Test
    @ContextConfiguration(classes = { ApplicationConfig.class })
    @DirtiesContext
    @WebAppConfiguration
    public class ATest extends AbstractTestNGSpringContextTests{
        @BeforeSuite
        public void setup() throws Throwable {
    
        }
        @AfterSuite
        public void teardown() {
    
        }
    }
    
    0 讨论(0)
  • 2021-01-07 04:53

    Caused by: javax.management.InstanceAlreadyExistsException: bean:name=testBean1

    This is trying to tell you that you have 2 beans with the same name ObjectName of bean:name=testBean1 being register with the MBeanExporter. However, unless there are other XML files or more entries in your beans map then there should not be.

    I have no even idea how to debug it.

    You could put a breakpoint in the JmxMBeanServer.registerMBean(...) method to see what beans are being registered to see if you can figure out why you are getting a duplicate.


    As an aside, my SimpleJMX library is an easy way to export your beans via JMX. There is pretty good Spring support as well. Here are the documentation about using with Spring. There is also a Spring test program which demonstrates what you need to do to get it working. Here's the Spring XML file.

    0 讨论(0)
提交回复
热议问题