16 組合註解與元註解

2021-09-11 02:36:36 字數 870 閱讀 9182

元註解:可以在註解類上進行的註解。

組合註解:當前註解類上有元註解。

使用自定義組合註解,合併配置類中的@configuration和@componentscan

@target(elementtype.type)

@retention(retentionpolicy.runtime)

@configuration

@componentscan

@documented

public @inte***ce assemble ;

}@target(elementtype.type):註解在類上

@retention(retentionpolicy.runtime):在jvm執行時讀取

@configuration:表示配置

@componentscan:自動掃瞄@component、@repository、@service、@controller放入容器

配置類:

@assemble("com.demo02.assemble")

public class assembleconfig

@assemble("com.demo02.assemble"):自定義組合註解。

bean:

@component

public class demo

}

測試執行:

@test

public void test01() }

自定義組合註解能被用於配置類中,避免每次定義配置類時,使用@configuration和@compontscan兩個註解,簡化**。

讀書筆記16 組合模式

概念 將物件組合成樹形結構以表示 部分 整體 的層次結構。組合模式使得使用者對單個物件和組合物件的使用具有一致性。角色component 組合中物件介面 leaf 葉子,繼承自component composite 分支,繼承自component 注意 這裡分為透明模式和安全模式,透明模式指,葉子和...

讀書筆記16 組合模式

概念 將物件組合成樹形結構以表示 部分 整體 的層次結構。組合模式使得使用者對單個物件和組合物件的使用具有一致性。角色component 組合中物件介面 leaf 葉子,繼承自component composite 分支,繼承自component 注意 這裡分為透明模式和安全模式,透明模式指,葉子和...

我與C 設計模式(八) 組合模式

組合模式,是為了解決整體和部分一直對待的問題而產生的,要求整體和部分有很多一致的操作。部分和整體繼承同乙個抽象幾口,這樣,外部使用時是一致的,同乙個方法能遍歷整體也能訪問部分。g o composite main.cpp composite.cpp結果 operation from leaf ope...