Merge branch '2.6.x' into 2.7.x

Closes gh-33328
pull/33648/head
Moritz Halbritter 2 years ago
commit d430779f00

@ -30,15 +30,12 @@ import org.springframework.context.annotation.Conditional;
* <p> * <p>
* A {@code Class} {@link #value() value} can be safely specified on * A {@code Class} {@link #value() value} can be safely specified on
* {@code @Configuration} classes as the annotation metadata is parsed by using ASM before * {@code @Configuration} classes as the annotation metadata is parsed by using ASM before
* the class is loaded. If a class reference cannot be used then a {@link #name() name} * the class is loaded. This only holds true if {@code @ConditionalOnClass} is used on a
* {@code String} attribute can be used. * class. Extra care must be taken when using {@code @ConditionalOnClass} on {@code @Bean}
* <p> * methods: the {@link #value() value} attribute must not be used, instead the
* <b>Note:</b> Extra care must be taken when using {@code @ConditionalOnClass} on * {@link #name() name} attribute can be used to reference the class which must be present
* {@code @Bean} methods where typically the return type is the target of the condition. * as a {@code String}. Alternatively create a separate {@code @Configuration} class that
* Before the condition on the method applies, the JVM will have loaded the class and * isolates the condition. For example: <pre class="code">
* potentially processed method references which will fail if the class is not present. To
* handle this scenario, a separate {@code @Configuration} class should be used to isolate
* the condition. For example: <pre class="code">
* &#064;AutoConfiguration * &#064;AutoConfiguration
* public class MyAutoConfiguration { * public class MyAutoConfiguration {
* *
@ -66,17 +63,21 @@ import org.springframework.context.annotation.Conditional;
public @interface ConditionalOnClass { public @interface ConditionalOnClass {
/** /**
* The classes that must be present. Since this annotation is parsed by loading class * The classes that must be present. Using this attribute is safe when using
* bytecode, it is safe to specify classes here that may ultimately not be on the * {@code ConditionalOnClass} at class level, but it must not be used when using
* classpath, only if this annotation is directly on the affected component and * {@code ConditionalOnClass} on a {@code @Bean} method.
* <b>not</b> if this annotation is used as a composed, meta-annotation. In order to * <p>
* use this annotation as a meta-annotation, only use the {@link #name} attribute. * Since this annotation is parsed by loading class bytecode, it is safe to specify
* classes here that may ultimately not be on the classpath, only if this annotation
* is directly on the affected component and <b>not</b> if this annotation is used as
* a composed, meta-annotation. In order to use this annotation as a meta-annotation,
* only use the {@link #name} attribute.
* @return the classes that must be present * @return the classes that must be present
*/ */
Class<?>[] value() default {}; Class<?>[] value() default {};
/** /**
* The classes names that must be present. * The class names that must be present.
* @return the class names that must be present. * @return the class names that must be present.
*/ */
String[] name() default {}; String[] name() default {};

Loading…
Cancel
Save