如何解决嵌入式ActiveMQ Artemis的ArtemisJMXSecurity实例未找到异常?
解决Spring Boot嵌入式ActiveMQ Artemis连接外部Hawtio时的JMX实例未找到异常
问题根源
这个异常是因为Hawtio连接时会自动查找Artemis专属的JMX安全Bean(hawtio:type=security,area=jmx,name=ArtemisJMXSecurity),但嵌入式Artemis默认不会注册这个Bean,导致每次连接都抛出实例未找到的错误。
可行解决方案
方案1:手动注册ArtemisJMXSecurity Bean
在Spring Boot的配置类里,通过JMX服务器手动注册这个缺失的Bean:
import org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ; import org.apache.activemq.artemis.jmx.ArtemisJMXSecurity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.annotation.PostConstruct; @Configuration public class ArtemisJmxConfig { @Autowired private EmbeddedActiveMQ embeddedActiveMQ; @Autowired private MBeanServer mBeanServer; @PostConstruct public void registerArtemisJmxSecurity() throws Exception { ArtemisJMXSecurity securityBean = new ArtemisJMXSecurity(embeddedActiveMQ.getActiveMQServer()); ObjectName objectName = new ObjectName("hawtio:type=security,area=jmx,name=ArtemisJMXSecurity"); if (!mBeanServer.isRegistered(objectName)) { mBeanServer.registerMBean(securityBean, objectName); } } }
方案2:禁用Hawtio的Artemis安全检查
如果不需要Artemis的JMX安全控制,直接在Hawtio的连接设置里加个参数:
- 连接嵌入式Artemis时,在JMX连接参数中添加
hawtio.disableArtemisSecurity=true,这样Hawtio就不会去查找那个安全Bean了。
方案3:调整Artemis嵌入式配置
在Spring Boot的配置文件里开启Artemis的JMX支持并指定域名,让安全Bean自动注册:
# application.properties spring.artemis.jmx.enabled=true spring.artemis.jmx.domain=hawtio
或者用YAML格式:
# application.yml spring: artemis: jmx: enabled: true domain: hawtio
验证
配置完成后重启Spring Boot应用,再用Hawtio连接嵌入式Artemis,检查日志应该就不会再出现那个异常了。
内容的提问来源于stack exchange,提问作者user2038596
相关产品推荐
相关产品推荐

