gpt4 book ai didi

spring - @EmbeddedKafka 试图多次注册 AppInfo mbean?

转载 作者:行者123 更新时间:2023-12-04 13:40:18 24 4
gpt4 key购买 nike

我使用@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)

最佳答案

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

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

关于spring - @EmbeddedKafka 试图多次注册 AppInfo mbean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58190533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com