Change @ManagedResource objectName dynamically

后端 未结 2 2064
囚心锁ツ
囚心锁ツ 2021-01-02 10:45

I am creating prototype beans programatically/dynamically. I want those beans after initiation to be in the jmx console. How I can distinguish between them? I am using anota

2条回答
  •  Happy的楠姐
    2021-01-02 11:27

    You can do this by just implementing org.springframework.jmx.export.naming.SelfNaming:

    @Component("MyPrototypeScopedBeanName")
    @ManagedResource     
    public class MyPrototypeScopedBeanName implements SelfNaming
    {
        @Override
        public ObjectName getObjectName() throws MalformedObjectNameException {
            return new ObjectName("com.foobar", "name", this.toString());
        }
    }
    

提交回复
热议问题