diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClass.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClass.java index ebc959dbd3e1..3a32320d6191 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClass.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClass.java @@ -36,9 +36,14 @@ public @interface ConditionalOnClass { /** + *

* The classes that must be present. Since this annotation parsed by loading class * bytecode it is safe to specify classes here that may ultimately not be on the - * classpath. + * classpath, only if this annotation is directly on the affected component and + * not if this annotation is used as a composed, meta-annotation. If this + * is used as a meta annotation and the given class is not available at runtime + * then this {@link @Conditional} will effectively be ignored. In order to use + * this annotation as a meta-annotation, only use the {@link #name} attribute. * @return the classes that must be present */ Class[] value() default {}; diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index c7311daa7b22..5453b902efec 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -6080,11 +6080,16 @@ code by annotating `@Configuration` classes or individual `@Bean` methods. [[boot-features-class-conditions]] ==== Class conditions The `@ConditionalOnClass` and `@ConditionalOnMissingClass` annotations allows -configuration to be included based on the presence or absence of specific classes. Due to -the fact that annotation metadata is parsed using http://asm.ow2.org/[ASM] you can -actually use the `value` attribute to refer to the real class, even though that class -might not actually appear on the running application classpath. You can also use the -`name` attribute if you prefer to specify the class name using a `String` value. +configuration to be included based on the presence or absence of specific classes. +If you are using the `@ConditionalOnClass` annotation directly on the class you are conditionally +registering, you can actually use the `value` attribute to refer to the real class, +even though that class might not actually appear on the running application classpath. +This is due to the fact that annotation metadata directly on a class is parsed +using http://asm.ow2.org/[ASM]. You can also use the `name` attribute if you prefer to +specify the class name using a `String` value, which is required if you are using +`@ConditionalOnClass` or `@ConditionalOnMissingClass` as apart of a meta-annotation to +compose your own composed annotations or in an `@Bean` method as neither of these cases +are handled by ASM.