使用弹簧4。我正在创建
SimpleMessageListenerContainer
来自的工厂方法
@Configuration @Bean
@Bean( name = "container" )
SimpleMessageListenerContainer container(){
...
...
如何在JMX上公开此实例?由于@ManagedResource只能应用于类
@Bean
public MBeanExporter exporter() {
MBeanExporter mBeanExporter = new MBeanExporter();
mBeanExporter.setBeans(
Collections.singletonMap("myDomain:type=container,name=myContainter", "container"));
return mBeanExporter;
}
这将公开所有公共方法/属性。如果你想限制哪些是暴露的,你可以使用MethodNameBasedMBeanInfoAssembler
:
@Bean
public MBeanExporter exporter() {
MBeanExporter mBeanExporter = new MBeanExporter();
mBeanExporter.setBeans(
Collections.singletonMap("myDomain:type=container,name=myContainter", "container"));
MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler();
assembler.setManagedMethods(new String[] { "start", "stop" });
mBeanExporter.setAssembler(assembler);
return mBeanExporter;
}