Skip to content

Commit d430779

Browse files
committed
Merge branch '2.6.x' into 2.7.x
Closes gh-33328
2 parents 1da3a9d + 2f6edec commit d430779

File tree

1 file changed

+16
-15
lines changed
  • spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition

1 file changed

+16
-15
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClass.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@
3030
* <p>
3131
* A {@code Class} {@link #value() value} can be safely specified on
3232
* {@code @Configuration} classes as the annotation metadata is parsed by using ASM before
33-
* the class is loaded. If a class reference cannot be used then a {@link #name() name}
34-
* {@code String} attribute can be used.
35-
* <p>
36-
* <b>Note:</b> Extra care must be taken when using {@code @ConditionalOnClass} on
37-
* {@code @Bean} methods where typically the return type is the target of the condition.
38-
* Before the condition on the method applies, the JVM will have loaded the class and
39-
* potentially processed method references which will fail if the class is not present. To
40-
* handle this scenario, a separate {@code @Configuration} class should be used to isolate
41-
* the condition. For example: <pre class="code">
33+
* the class is loaded. This only holds true if {@code @ConditionalOnClass} is used on a
34+
* class. Extra care must be taken when using {@code @ConditionalOnClass} on {@code @Bean}
35+
* methods: the {@link #value() value} attribute must not be used, instead the
36+
* {@link #name() name} attribute can be used to reference the class which must be present
37+
* as a {@code String}. Alternatively create a separate {@code @Configuration} class that
38+
* isolates the condition. For example: <pre class="code">
4239
* &#064;AutoConfiguration
4340
* public class MyAutoConfiguration {
4441
*
@@ -66,17 +63,21 @@
6663
public @interface ConditionalOnClass {
6764

6865
/**
69-
* The classes that must be present. Since this annotation is parsed by loading class
70-
* bytecode, it is safe to specify classes here that may ultimately not be on the
71-
* classpath, only if this annotation is directly on the affected component and
72-
* <b>not</b> if this annotation is used as a composed, meta-annotation. In order to
73-
* use this annotation as a meta-annotation, only use the {@link #name} attribute.
66+
* The classes that must be present. Using this attribute is safe when using
67+
* {@code ConditionalOnClass} at class level, but it must not be used when using
68+
* {@code ConditionalOnClass} on a {@code @Bean} method.
69+
* <p>
70+
* Since this annotation is parsed by loading class bytecode, it is safe to specify
71+
* classes here that may ultimately not be on the classpath, only if this annotation
72+
* is directly on the affected component and <b>not</b> if this annotation is used as
73+
* a composed, meta-annotation. In order to use this annotation as a meta-annotation,
74+
* only use the {@link #name} attribute.
7475
* @return the classes that must be present
7576
*/
7677
Class<?>[] value() default {};
7778

7879
/**
79-
* The classes names that must be present.
80+
* The class names that must be present.
8081
* @return the class names that must be present.
8182
*/
8283
String[] name() default {};

0 commit comments

Comments
 (0)