Introduction of conditional in Spring-boot

Source: Internet
Author: User

Original address: http://www.jianshu.com/p/0740c07f6c1d

@Conditional

The Official document defines: "indicates that a component was only eligible to registration when all specified conditions match" means only after some column conditions have been met to create A bean. @Conditional definition

@Retention (retentionpolicy.runtime)
@Target ({elementtype.type, elementtype.method}) public
@interface Conditional {
    class<? extends condition>[] value ();
}

@Conditional annotations are primarily used in the following locations: class level can be placed on a class labeled @component (containing @configuration) as a meta-annotation, which makes up a custom annotation The method level can be placed on the @conditional series that identifies the Spring-boot method on the @bean

Spring-boot uses conditional to determine if a bean instance is to be created, as the official note below, presumably boot is to enable the @conditional annotation to determine if the instance is to be loaded. Boot is an enabled in Spring Framework 4.0 by the @Conditional annotation infrastructure. Your perception of loaded is accurate Otherwise-jrebel are much more comprehensive, works with multiple IDEs, etc. Conditionalonbean: An instance of the class that marks the annotation is created when and only if the specified bean classes and/or bean names in the current container Conditionalonmissingbean: When and only if the specified bean Classes and/or bean names does not exist in the current container to create an instance of the class on which the annotation is marked, there are parameters that specify ignore ignored, you can omit class, type, and so on Conditionalonclass: An instance of the class that marks the annotation is created when and only if classpath exists in the specified class Conditionalonmissingclass: When and only if the specified class is not present in the classpath. Create an instance of the class on which the annotation is marked Conditionalonproperty: Creates an instance of the class that marks the annotation if and only if the specified configuration item exists in Application.properties Conditionalonjava: Specifies version conditionalonexpression of JDK: Expression with ${...} =false to indicate that Conditionalonjndi:jndi exists when the item is created Conditionalonresource: created when a specified resource exists under Classpath Conditionalonsinglecandidate:conditional that only matches when the specified bean class was already contained in the BEANF Actory and a single candidate can beDetermined. The condition would also match if multiple matching bean instances is already contained in the beanfactory but a primary c Andidate has been defined; Essentially, the condition match if auto-wiring a bean with the defined type would succeed. Conditionalonwebapplication: Creating in a Web environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.