|
30 | 30 | * <p>
|
31 | 31 | * A {@code Class} {@link #value() value} can be safely specified on
|
32 | 32 | * {@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"> |
42 | 39 | * @AutoConfiguration
|
43 | 40 | * public class MyAutoConfiguration {
|
44 | 41 | *
|
|
66 | 63 | public @interface ConditionalOnClass {
|
67 | 64 |
|
68 | 65 | /**
|
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. |
74 | 75 | * @return the classes that must be present
|
75 | 76 | */
|
76 | 77 | Class<?>[] value() default {};
|
77 | 78 |
|
78 | 79 | /**
|
79 |
| - * The classes names that must be present. |
| 80 | + * The class names that must be present. |
80 | 81 | * @return the class names that must be present.
|
81 | 82 | */
|
82 | 83 | String[] name() default {};
|
|
0 commit comments