package ch2.annotation;

//target/elementType用来设定注解的使用范围
import java.lang.annotation.ElementType;
import java.lang.annotation.Target; //表明这个注解documented会被javac工具记录
import java.lang.annotation.Documented; //retention/retentionPolicy(保留)注解,在编译的时候会被保留在某个(那个)特定的编译阶段
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; //target/elementType用来设定注解的使用范围:type用于类或接口上
@Target(ElementType.TYPE) //retention/retentionPolicy(保留)注解,在编译的时候会被保留在某个(那个)特定的编译阶段
//这种类型的Annotations将被JVM保留
@Retention(RetentionPolicy.RUNTIME) //表明这个注解@documented会被javac工具记录
@Documented //组合注解
//组合configuration元注解
@Configuration
//组合ComponentScan元注解
@ComponentScan //组合注解
public @interface WiselyConfiguration { //覆盖value参数
String[] value() default{}; }

  

package ch2.annotation;

import org.springframework.stereotype.Service;

//声明为spring的组件
@Service //演示服务Bean
public class DemoService { public void outputResult()
{
System.out.println("从组合注解配置里,照样获得Bean");
} }

  

package ch2.annotation;

//引入ch2.annotation下的包
//使用wiselyConfiguration组合注解代替@ComponentScan,@Configuration
@WiselyConfiguration("ch2.annotation") //新的配置类
public class DemoConfig { }

  

package ch2.annotation;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main {

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

  

spring boot: 组合注解与元注解的更多相关文章

  1. Spring Boot实战笔记(九)-- Spring高级话题(组合注解与元注解)

    一.组合注解与元注解 从Spring 2开始,为了响应JDK 1.5推出的注解功能,Spring开始大量加入注解来替代xml配置.Spring的注解主要用来配置注入Bean,切面相关配置(@Trans ...

  2. 曹工说Spring Boot源码(23)-- ASM又立功了,Spring原来是这么递归获取注解的元注解的

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  3. Spring组合注解与元注解

    目录 注解说明 源代码 使用范例 注解说明 元注解:可以注解到别的注解上的注解,所以元注解首先基于条件@Target({ElementType.TYPE}) ,目标使用在类文件上 . 组合注解:连个元 ...

  4. [读书笔记] 二、条件注解@Conditional,组合注解,元注解

    一.条件注解@Conditional,组合注解,元注解 1. @Conditional:满足特定条件创建一个Bean,SpringBoot就是利用这个特性进行自动配置的. 例子: 首先,两个Condi ...

  5. spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,guava限流,定时任务案例, 发邮件

    本文介绍spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,定时任务案例 集成swagger--对于做前后端分离的项目,后端只需要提供接口访问,swagger提供了接口 ...

  6. Spring Boot 2.0 教程 | @ModelAttribute 注解

    欢迎关注微信公众号: 小哈学Java 文章首发于个人网站: https://www.exception.site/springboot/spring-boot-model-attribute Spri ...

  7. spring源码解析:元注解功能的实现

    前言 众所周知,spring 从 2.5 版本以后开始支持使用注解代替繁琐的 xml 配置,到了 springboot 更是全面拥抱了注解式配置.平时在使用的时候,点开一些常见的等注解,会发现往往在一 ...

  8. Spring----组合注解与元注解

    1.概述 1.1.Spring提供了大量的注解, 尤其是相同的注解用到各个类中,会相当的啰嗦: 1.2.元注解: 可以注解到别的注解上的注解: 组合注解: 被注解注解的注解称为 组合注解: 组合注解  ...

  9. JavaEE开发之Spring中的条件注解组合注解与元注解

    上篇博客我们详细的聊了<JavaEE开发之Spring中的多线程编程以及任务定时器详解>,本篇博客我们就来聊聊条件注解@Conditional以及组合条件.条件注解说简单点就是根据特定的条 ...

随机推荐

  1. 小程序html 显示 图片处理

    let arr = [] for (const v of r.data.data ){ // v.content = v.content.replace(/<img/g ,' <image ...

  2. "大中台、小前台”新架构下,阿里大数据接下来怎么玩? (2016-01-05 11:39:50)

    "大中台.小前台”新架构下,阿里大数据接下来怎么玩?_炬鼎力_新浪博客 http://blog.sina.com.cn/s/blog_1427354e00102vzyq.html " ...

  3. 烂代码 git blame

    关于烂代码的那些事(上) - Axb的自我修养 http://blog.2baxb.me/archives/1343 关于烂代码的那些事(上) 六月 21, 2015 57 条评论 目录 [显示] 1 ...

  4. delphi下webbrowser的应用

    查找操作tagName为input的对象var i:Integer; myole:oleVariant; begin myole := wb1.Document; for i := 0 to myol ...

  5. POI解析Excel封装工具

    1. [代码][Java]代码     跳至 [1] [全屏预览] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 ...

  6. Linux中的环境变量配置文件及其作用

    登录相关的配置文件: /etc/profile 范围:对所有用户生效 作用: a.定义USER变量 b.定义LOGNAME变量 c.定义MAIL变量 d.定义PATH变量 e.定义HOSTNAME变量 ...

  7. ubuntu安装deb文件

    install the deb-package, e.g. using the Terminal command$ sudo apt install <path-to-smartgit-deb- ...

  8. github常用的git命令

    添加已有项目到github: touch README.md //新建说明文件 git init //在当前项目目录中生成本地git管理,并建立一个隐藏.git目录 git add . //添加当前目 ...

  9. myql命令

    ALTER TABLE 表名 DROP COLUMN 列名#删除某一列

  10. node做验证码

    使用了ccap插件 1.安装: 通用方法:npm install ccap 2. cnst ccap= require('ccap')({ width: 128, height: 40, offset ...