首页 > 其他分享 >@Conditional注解

@Conditional注解

时间:2023-07-29 14:22:41浏览次数:30  
标签:Conditional class Bean 注解 Configuration annotation

1.介绍@Conditional注解

@Conditional注解源码

@Conditionl注解简单说明

@Conditional注解所属包
org.springframework.context.annotation.Conditional
注解作用范围
{ElementType.TYPE, ElementType.METHOD}
类、接口、注解、枚举以及 方法
注解生命周期
@Retention(RetentionPolicy.RUNTIME)
代码编译为.class文件后,注解仍然存在,而且能被虚拟机识别,可以通过反射获取到

2.@Conditional注解的用法

Indicates that a component is only eligible for registration when all specified conditions match.

仅当所有条件被满足时组件才有资格被注册进容器中

The @Conditional annotation may be used in any of the following ways:

1.as a type-level annotation on any class directly or indirectly annotated with @Component, including @Configuration classes

2.as a meta-annotation, for the purpose of composing custom stereotype annotations

3.as a method-level annotation on any @Bean method

@Conditional注解可能用在以下这些场景中

1.作为一个type级别的注解,在任何被@Component注解包括@Configuration注解注解或者间接修饰的类上使用;

2.作为元注释,用于组合自定义构造型注释

3.作为method级别注解在任何被@Bean修饰的方法上

If a @Configuration class is marked with @Conditional, all of the @Bean methods, @Import annotations, and @ComponentScan annotations associated with that class will be subject to the conditions.

如果@Configuration类被标记为@Conditional,那么与该类关联的所有@Bean方法、@Import注解和@ComponentScan注解都将受这些条件的约束。

 

标签:Conditional,class,Bean,注解,Configuration,annotation
From: https://www.cnblogs.com/hyl-blog/p/17589747.html

相关文章

  • Spring,SpringMVC,Spring Boot中常见注解(持续更新)
    在学习Java框架时,注解的学习是必不可少的,这篇文章就来记录一下这些框架中的常用注解(常用注解)一,spring1.声明bean的注解@Component组件,没有明确的角色@Service在业务逻辑层使用(service层)@Repository在数据访问层使用(dao层)@Controller在展现层使用,控制器的声明......
  • 条件随机场(conditional random field,CRF)模型初探
    条件随机场(conditionalrandomfield,CRF)模型初探1.条件随机场,一种特殊的概率图模型结构我们知道,从图结构角度来说,概率图模型可以分为以下两种:基于有向图的贝叶斯网:具备有向依赖性基于无向图的马尔科夫网:具备无向依赖性条件随机场是一个在变量子集上存在有......
  • @Configuration注解的作用
    @Configuration可理解为用spring的时候xml里面的<beans>标签@Bean可理解为用spring的时候xml里面的<bean>标签参考:https://blog.csdn.net/liuyinfei_java/article/details/820118051、第一种自己写的类,Controller,Service。用@controller@service即可2、第二种,集成其它框架,比......
  • linux注解:单行注解 | 多行注解
    摘要linux单行注解linux多行注解一、shell单行注解用#来实现单行注解#echohello二、shell多行注解用:<<!!实现多行注解:<<!echohelloworldechohelloworld2!......
  • @Data注解
    @Data注解的主要作用是提高代码的简洁,使用这个注解可以省中大量的get()、set()、toString()等方法。 ......
  • @Accessors注解——Lombok的链式编程
    用注解@Accessors 给实体类加上 chain=true 选项,即@Accessors(chain=true) 支持了Java链式写法; 什么是链式写法,比如:report.getOne().getTwo().getId(); 相关连接:https://susu-math.blog.csdn.net/article/details/122770688?spm=1001.2101.3001.6650.1&utm_me......
  • @ Transient注解
    @transient就是在给某个javabean上需要添加个属性,但是这个属性你又不希望给存到数据库中去,仅仅是做个临时变量,用一下。不修改已经存在数据库的数据的数据结构。 相关链接:https://blog.csdn.net/rongxiang111/article/details/86476028......
  • @GeneratedValue 和 @GenericGenerator注解----自定义主键生成策略
    @GeneratedValue注解存在的意义主要就是为一个实体生成一个唯一标识的主键 https://blog.csdn.net/sswqzx/article/details/84337921https://blog.csdn.net/u011781521/article/details/72210980......
  • java 时间转换注解 HH:mm
    Java时间转换注解HH:mm在Java开发中,经常需要对时间进行转换和格式化操作。例如,将时间从一种格式转换为另一种格式,或者将时间字符串解析为Java的日期对象。然而,这些操作可能会变得繁琐和冗长。为了简化这些操作,我们可以使用Java时间转换注解。什么是时间转换注解?时间转换注解是......
  • 寻找解析注解的类
    1、直接搜索"注解名.class"以若依项目为例,我要寻找如下注解的解析情况/***自定义注解防止表单重复提交**@authorruoyi**/@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)@Documentedpublic@interfaceRepeatSubmit{/***间隔......