4

我使用@EmbeddedKafka 进行了多个集成测试,在迁移到更新的 springboot 版本 2.1.8.RELEASE 后,日志中充满了这些堆栈跟踪。知道是什么原因造成的吗?

javax.management.InstanceAlreadyExistsException: kafka.server:type=app-info,id=0
    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.apache.kafka.common.utils.AppInfoParser.registerAppInfo(AppInfoParser.java:62)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:321)
    at kafka.utils.TestUtils$.createServer(TestUtils.scala:132)
    at kafka.utils.TestUtils.createServer(TestUtils.scala)
    at org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:223)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:405)
4

1 回答 1

1

如果您的测试使用的是 Spring 测试上下文(@RunWith(SpringRunner.class), @SpringJUnitConfig, @SpringBootTest等),那么嵌入式 kafka 将存储在应用程序上下文中。

添加@DirtiesContext到每个测试类,以便正确处理实例。

于 2019-10-01T18:49:14.433 回答