@Conditional related notes

@Conditional Spring4 annotation is newly provided, its role is determined according to certain conditions, the condition register to the container bean.

@Conditional definition:

// This annotation can be marked on the classes and methods
@Target ({ElementType.TYPE, ElementType.METHOD})
@Retention (RetentionPolicy.RUNTIME)
@Documented
public @interface the Conditional {
Class [] value () <the extends for condition Condition?>;
}
can be seen from the code, the need to pass a Class array, and the need to extend the Condition interface:

interface for condition Condition {public
Boolean matches (ConditionContext var1, var2 AnnotatedTypeMetadata);
}
for condition Condition interfaces is required to achieve matches method returns true injection bean, false not injected.
https://blog.csdn.net/xcy1193068639/article/details/81491071

 

Spring framework also provides a lot of @Condition them to us, of course, the terms of which are summarized well understood, readers look to myself

@ConditionalOnProPerty: meets the definition of a given parameter value is set to meet on the load, no load does not meet https://blog.csdn.net/u010002184/article/details/79353696

@ConditionalOnBean (When an object is present only in the current context, will instantiate a Bean)
@ConditionalOnClass (a class on the classpath, will instantiate a Bean)
@ConditionalOnExpression (the time when the expression is true, will instantiate a Bean)
when @ConditionalOnMissingBean (only an object does not exist in the current context, will instantiate a Bean)
@ConditionalOnMissingClass (class does not exist on a time-based path, will instantiate a Bean)
@ConditionalOnNotWebApplication (not a web application)

Follow-up will continue to add

Another summary

@ConditionalOnClass: parameters of the corresponding annotation class must exist, or do not resolve the modified configuration class notes;
@ConditionalOnMissingBean: The comment said that if it is modified bean classes exist, do not need to create the bean; give the annotation parameters passed e.g. @ConditionOnMissingBean (name = "example") , if the name is represented by "example" of the bean exists, the annotation which does not execute the modified code blocks
-------------- -------
author: less prodigal son Yan
source: CSDN
original: https: //blog.csdn.net/win7system/article/details/54377471
copyright: This article is a blogger original article, reproduced, please attach a link Bowen !

Guess you like

Origin www.cnblogs.com/suntp/p/10156466.html
Recommended