Ensure single instance of a spring managed bean

后端 未结 3 1183
执笔经年
执笔经年 2021-01-16 13:05

I have created a spring aspect to handle Retry mechanism. I have also created a Retry annotation. Following is the code for Retry annotation and an aspect which processes th

3条回答
  •  走了就别回头了
    2021-01-16 13:32

    1. if someone can create second bean of your type, why you are don't want to check someone creates another aspect with same logic? I think your approach is erroneous by design.
    2. you can implement ApplicationContextAware interface and check there, that only one bean of your class present in context and throw exception if it's not true, but I'm not sure that this will work if you have context hierarchy.

提交回复
热议问题