[英]Conditional initiation of group of beans by property
在我的Spring Boot應用程序中,我有許多負責監視的bean。 今天,每個注釋都帶有:
@ConditionalOnProperty(name="enable.monitor", havingValue="true")
這樣,監視是完全可配置的,我可以從屬性文件中打開和關閉它。
我在此解決方案中不喜歡的事情是必須將這個長注釋添加到每個bean。 我想知道是否有更優雅的方法來實現這種可配置的監視。 也許通過用@Monitoring
新注釋對所有bean進行注釋,然后以某種方式告訴spring根據該屬性啟動它們,這可能嗎?
歡迎其他任何建議。
可以創建自己的自定義@Monitoring
批注,如下所示:
Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ConditionalOnProperty(name="enable.monitor", havingValue="true")
public @interface Monitoring {
}
此后可以將其應用於其他bean。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.