通過(guò)實(shí)例解析Spring組合注解與元注解
這篇文章主要介紹了通過(guò)實(shí)例解析Spring組合注解與元注解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
1、概述
1.1、Spring提供了大量的注解,
尤其是相同的注解用到各個(gè)類中,會(huì)相當(dāng)?shù)膯拢?/p>
1.2、元注解:
可以注解到別的注解上的注解;
組合注解:
被注解注解的注解稱為 組合注解;
組合注解 具備 元注解 的功能,Spring的很多注解都可以作為元注解;
1.3、案例
package com.an.config; import com.an.annotation.MyAnnotation; /** * @description: * @author: anpeiyong * @date: Created in 2019/11/21 8:57 * @since: */ @MyAnnotation(value = "com.an") public class AnnotationConfig { }
package com.an.annotation; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * @description: * @author: anpeiyong * @date: Created in 2019/11/21 8:47 * @since: */ @Target(value = ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Configuration @ComponentScan public @interface MyAnnotation { String[] value() default {}; }
package com.an.annotation; import org.springframework.stereotype.Service; /** * @description: * @author: anpeiyong * @date: Created in 2019/11/21 8:54 * @since: */ @Service public class AnnotationService { public void output(){ System.out.println("組合注解成功。。。"); } }
package com.an.main; import com.an.annotation.AnnotationService; import com.an.config.AnnotationConfig; import org.springframework.context.annotation.AnnotationConfigApplicationContext; /** * @description: * @author: anpeiyong * @date: Created in 2019/11/21 8:57 * @since: */ public class AnnotationMainTest { public static void main(String[] args) { AnnotationConfigApplicationContext annotationConfigApplicationContext=new AnnotationConfigApplicationContext(AnnotationConfig.class); AnnotationService annotationService=annotationConfigApplicationContext.getBean(AnnotationService.class); annotationService.output(); annotationConfigApplicationContext.close(); } }
結(jié)果:
組合注解成功。。。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于SpringBoot核心原理(自動(dòng)配置、事件驅(qū)動(dòng)、Condition)
這篇文章主要介紹了基于SpringBoot核心原理(自動(dòng)配置、事件驅(qū)動(dòng)、Condition),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08SpringBoot接受前臺(tái)參數(shù)的6種方式以及統(tǒng)一響應(yīng)代碼示例
這篇文章主要給大家介紹了關(guān)于SpringBoot接受前臺(tái)參數(shù)的6種方式以及統(tǒng)一響應(yīng)的相關(guān)資料,前端負(fù)責(zé)展示頁(yè)面和用戶交互,而后端則負(fù)責(zé)處理業(yè)務(wù)邏輯和數(shù)據(jù)存儲(chǔ),在這種架構(gòu)下前端需要將用戶輸入的數(shù)據(jù)發(fā)送給后端進(jìn)行處理,需要的朋友可以參考下2023-12-12Java tomcat環(huán)境變量及idea配置解析
這篇文章主要介紹了Java tomcat環(huán)境變量及idea配置解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12Java實(shí)現(xiàn)對(duì)象列表導(dǎo)出為excel表格的實(shí)用工具類
這篇文章主要為大家詳細(xì)介紹了Java如何實(shí)現(xiàn)對(duì)象列表導(dǎo)出為excel表格的實(shí)用工具類,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12Java調(diào)用MySQL存儲(chǔ)過(guò)程并獲得返回值的方法
這篇文章主要介紹了Java調(diào)用MySQL存儲(chǔ)過(guò)程并獲得返回值的方法,實(shí)例分析了java實(shí)現(xiàn)MySQL存儲(chǔ)過(guò)程的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07java?中如何實(shí)現(xiàn)?List?集合去重
這篇文章主要介紹了java?中如何實(shí)現(xiàn)?List?集合去重,List?去重指的是將?List?中的重復(fù)元素刪除掉的過(guò)程,下文操作操作過(guò)程介紹需要的小伙伴可以參考一下2022-05-05將RestTemplate的編碼格式改為UTF-8,防止亂碼問(wèn)題
這篇文章主要介紹了將RestTemplate的編碼格式改為UTF-8,防止亂碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10