Non Singleton(原型)Spring bean JMX moniterable

时间:2015-04-26 11:54:35

标签: java spring mbeans spring-jmx mbeanexporter

我是Spring JMX的新手。我想通过Spring JMX监视项目中的原型bean,我创建了一个示例项目来注册一个正在运行的Spring的MbeanExporter的bean(Singleton)。然后我用谷歌搜索用Spring JMX注册Non-Singleton bean并监控它,但我没有发现任何有用的东西。

我遇到了描述我的问题的Spring forum post,但答案并非如此。

1 个答案:

答案 0 :(得分:1)

我一直在谷歌搜索这个问题,我在stackoverlow本身发现了一些真正帮助我的帖子。只需复制代码: -

 @Component("MyPrototypeScopedBeanName")
 @Scope(value = "prototype")
 @ManagedResource     
 public class MyPrototypeScopedBeanName implements SelfNaming

 @Autowired
 MBeanExporter exporter;
 .
 .
 @PostConstruct
 private void init() throws Exception {
    exporter.registerManagedResource(this);
 }
 .
 .
 .

 @Override
 public ObjectName getObjectName() throws MalformedObjectNameException {
     return new ObjectName("com.foobar", "name", this.toString());
 }

此外,您可能希望将导出器配置为在自动检测期间忽略它,因为自动检测与原型一起使用的方式,它将为自己创建另一个实例,它将向JMX控制台添加一个额外的实例。

<property name="autodetect" value="true"/>
<!--  Done to prevent creation of additional prototype during autodetect routine -->
<property name="excludedBeans">
    <list>
        <value>MyPrototypeScopedBeanName</value>
    </list>
</property>

Stackoverflow link

Another link

礼貌: - @theJC

相关问题