Spring中常用註解
阿新 • • 發佈:2018-12-18
[email protected]註解
@Value 為屬性注入值(該註解貼在屬性上)
支援如下方式的注入:
(1)注入普通字元
@Value(“Michael Jackson”)String name;(2)注入作業系統屬性
@Value(“#{systemProperties[‘os.name’]}”)String osName;
(3)注入表示式結果
@Value(“#{ T(java.lang.Math).random() * 100 }”) String randomNumber;
(4)注入其它bean屬性
@Value(“#{domeClass.name}”)String name;(5)注入檔案資源
@Value(“classpath:cn/wolfocde/demo/test.txt”)String Resource file;
(6)注入網站資源
@Value(“http://www.wolfcode.cn")Resource url;(7)注入配置檔案
Value(“${user.name}”)String bookName;
2.切面(AOP)相關注解
Spring支援AspectJ的註解式切面程式設計。 @Aspect 宣告一個切面(該註解貼在類上) 使用@After、@Before、@Around定義建言(advice),可直接將攔截規則(切點)作為引數。 @After 在方法執行之後執行(該註解貼在方法上) @Before 在方法執行之前執行(該註解貼在方法上) @Around 在方法執行之前與之後執行(該註解貼在方法上) @PointCut 宣告切點在java配置類中使用@EnableAspectJAutoProxy註解開啟Spring對AspectJ代理的支援(該註解貼在類上)