佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > JSP 中Spring組合注解與元注解實例詳解

JSP 中Spring組合注解與元注解實例詳解

熱門標簽:Linux服務器 銀行業(yè)務 電子圍欄 服務器配置 Mysql連接數設置 科大訊飛語音識別系統 阿里云 團購網站

JSP 中Spring組合注解與元注解實例詳解

摘要: 注解(Annotation),也叫元數據。一種代碼級別的說明。它與類、接口、枚舉是在同一個層次。它可以聲明在包、類、字段、方法、局部變量、方法參數等的前面,用來對這些元素進行說明

1. 可以注解到別的注解上的注解稱為元注解,被注解的注解稱為組合注解,通過組合注解可以很好的簡化好多重復性的注解操作

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參數

3. 編寫普通Bean

@Servicepublic class DemoService
 { 
 public void sys()
 {   System.out.println("組合注解示例"); 
 }
}

4. 使用組合注解的配置類

@GroupAnnotation("com.xuanwu.annotation")
public class DemoConfig {
}

5. 運行

public class Main {
  public static void main(String[] args) {
   AnnotationConfigApplicationContext context = new
      AnnotationConfigApplicationContext(DemoConfig.class);
   DemoService demoService = context.getBean(DemoService.class);
   demoService.sys();
  }
}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

您可能感興趣的文章:
  • Spring mvc Controller和RestFul原理解析
  • SpringBoot http請求注解@RestController原理解析
  • Spring注解@RestControllerAdvice原理解析
  • 通過實例解析Spring組合注解與元注解
  • Spring的組合注解和元注解原理與用法詳解
  • 解決沒有@RunWith 和 @SpringBootTest注解或失效問題
  • Spring @Configuration注解及配置方法
  • Spring @RestController注解組合實現方法解析

標簽:衢州 蚌埠 棗莊 萍鄉(xiāng) 衡水 廣元 江蘇 大理

巨人網絡通訊聲明:本文標題《JSP 中Spring組合注解與元注解實例詳解》,本文關鍵詞  ;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    庄河市| 突泉县| 宜阳县| 科技| 晴隆县| 巴中市| 平乐县| 岱山县| 准格尔旗| 朝阳区| 兴宁市| 海口市| 康平县| 新安县| 九寨沟县| 东丰县| 山东省| 龙门县| 常宁市| 汕尾市| 沁阳市| 高唐县| 麻栗坡县| 沽源县| 陇西县| 东兰县| 榆林市| 巫山县| 孟津县| 长海县| 高阳县| 东乡族自治县| 博野县| 临武县| 砚山县| 上虞市| 武隆县| 淳化县| 北辰区| 东莞市| 大邑县|