当我使用Spring AMQP部署2个软件包时,在以下代码中出现JMX错误:
@Bean
public CachingConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(HOST);
connectionFactory.setBeanName("Test_123");
return connectionFactory;
}
我错误Caused by: 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=*
但是我遇到同样的错误。
答案 0 :(得分:1)
解决方案:
... 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);
}
}