spring掃瞄自定義註解並進行操作

2021-07-02 02:40:16 字數 744 閱讀 9793

今天又個需求,就是根據註解來判斷是否介面為對外開放,那麼啟動spring容器的時候把這些註解修飾的bean name放進快取當中。

/*** 掃瞄註解新增服務到快取以供判斷時候為對外開放service

*/@component

@lazy(true)

class annotationscannerconfigurer implements beandefinitionregistrypostprocessor

@override

public void postprocessbeanfactory(configurablelistablebeanfactory postprocessbeanfactory) throws bean***ception }}

我的annotationscannerconfigurer  實現了beandefinitionregistrypostprocessor ,spring啟動時會執行postprocessbeanfactory方法,通過postprocessbeanfactory我們就可以拿到@remotetag所修飾的bean了。然後隨你怎麼操作。

使用beandefinitionregistrypostprocessor 是從mybaties的spring掃瞄實現類得到靈感的。

注意:@lazy(true)是因為最後載入才能確保把所有@remotetag修飾的bean得到並進行操作。

Spring 自定義註解案例

1.自定義時間格式註解 target elementtype.field 作用於字段上 retention retentionpolicy.runtime 保留到執行期 public inte ce dateparse2.自定義資料字典註解 target elementtype.field 作用於字...

spring中使用自定義註解

使用spring時,aop可以大幅度減少我們的工作量,這裡主要介紹一些spring中aop如何切註解。自定義註解 target retention retentionpolicy.runtime public inte ce myannotation 編寫切面類,切點在自定義註解上,切面類新增到sp...

自定義註解

target elementtype.field retention retentionpolicy.runtime public inte ce setvalue以上就是乙個自定義的註解,下面來進行說明。target elementtype.field 表示支援該註解的程式元素,field就是屬性...