经过研究和使用spring boot,我了解 spring 启动ConditionalOnClass背后的用法和逻辑,我的问题是:
-
为什么"Since this annotation is parsed by loading class bytecode, it is safe to specify classes here that may ultimately not be on the classpath" .
-
与此相关的JVM规范在哪里?
/**
* The classes that must be present. 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
*/
Class<?>[] value() default {};
1 回答
因为Spring捕获ClassNotFoundException . 检查源代码 - https://github.com/spring-projects/spring-boot/blob/d3c34ee3d1bfd3db4a98678c524e145ef9bca51c/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnClassCondition.java#L218