gpt4 book ai didi

java - 设置唯一的 bean 名称 javax.management.InstanceAlreadyExistsException

转载 作者:行者123 更新时间:2023-12-02 11:02:21 31 4
gpt4 key购买 nike

当我使用 Spring AMQP 部署 2 个包时,我在以下代码中收到 JMX 错误:

    @Bean
public CachingConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(HOST);
connectionFactory.setBeanName("Test_123");
return connectionFactory;
}

我错误引起:javax.management.InstanceAlreadyExistsException:org.springframework.amqp.rabbit.connection:name=connectionFactory,type=CachingConnectionFactory

完整错误堆栈: https://pastebin.com/CdU3epMz

如何为connectionFactory设置唯一的名称?

编辑:

我还尝试将 application.properties 放置在 src/main/java/resources 下,此配置:

spring.jmx.enabled=false
spring.datasource.jmx-enabled=false
spring.jmx.default-domain=ssds # JMX domain name.
spring.jmx.server=apiServer # MBeanServer bean name.
management.metrics.export.jmx.domain=metccriddcs # Metrics JMX domain name.
management.metrics.export.jmx.enabled=false # Whether exporting of metrics to JMX is enabled.
management.endpoints.jmx.exposure.exclude=*

但我遇到了同样的错误。

最佳答案

解决办法:

... implements ObjectNamingStrategy {

@Override
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
Class managedClass = AopUtils.getTargetClass(managedBean);
String domain = ClassUtils.getPackageName(managedClass);

Hashtable<String, String> properties = new Hashtable<>();
properties.put("type", ClassUtils.getShortName(managedClass));
properties.put("name", "asdsdsd");
// ensure the application name is included as a property in the object name
properties.put("app", "api");
return ObjectNameManager.getInstance(domain, properties);
}

}

关于java - 设置唯一的 bean 名称 javax.management.InstanceAlreadyExistsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51230653/

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