I have got a SPRING application. When I run
mvn jetty:run
everything is ok.
I would like to use JMX
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() {
}
}