JSP 中Spring組合注解與元注解實(shí)例詳解
JSP 中Spring組合注解與元注解實(shí)例詳解
摘要: 注解(Annotation),也叫元數(shù)據(jù)。一種代碼級別的說明。它與類、接口、枚舉是在同一個(gè)層次。它可以聲明在包、類、字段、方法、局部變量、方法參數(shù)等的前面,用來對這些元素進(jìn)行說明
1. 可以注解到別的注解上的注解稱為元注解,被注解的注解稱為組合注解,通過組合注解可以很好的簡化好多重復(fù)性的注解操作
2. 示例組合注解
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
@ComponentScan
public @interface GroupAnnotation {
String[] value() default {};
}
代碼解釋:組合@Configuration 與 @ComponentScan 元注解,并覆蓋value參數(shù)
3. 編寫普通Bean
@Servicepublic class DemoService
{
public void sys()
{ System.out.println("組合注解示例");
}
}
4. 使用組合注解的配置類
@GroupAnnotation("com.xuanwu.annotation")
public class DemoConfig {
}
5. 運(yùn)行
public class Main {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new
AnnotationConfigApplicationContext(DemoConfig.class);
DemoService demoService = context.getBean(DemoService.class);
demoService.sys();
}
}
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
jsp 使用jstl實(shí)現(xiàn)翻頁實(shí)例代碼
這篇文章主要介紹了jsp 使用jstl實(shí)現(xiàn)翻頁實(shí)例代碼,有需要的朋友可以參考一下2013-12-12
JAVA/JSP學(xué)習(xí)系列之四(Orion App Server的安裝)
JAVA/JSP學(xué)習(xí)系列之四(Orion App Server的安裝)...2006-10-10
JSP中Servlet的Request與Response的用法與區(qū)別
這篇文章主要介紹了JSP中Servlet的Request與Response的用法與區(qū)別的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-09-09
jsp簡單連接SQL Server2000數(shù)據(jù)庫的方法
這篇文章主要介紹了jsp簡單連接SQL Server2000數(shù)據(jù)庫的方法,較為詳細(xì)的分析了JSP連接SQL Server2000數(shù)據(jù)庫的相關(guān)設(shè)置技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
教你怎么用JSP統(tǒng)計(jì)網(wǎng)站訪問人數(shù)
這篇文章主要介紹了教你怎么用JSP統(tǒng)計(jì)網(wǎng)站訪問人數(shù),文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)JSP的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04

