首页 文章

ConditionalOnClass,为什么JVM允许类在运行时不在类路径中

提问于
浏览
0

经过研究和使用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规范在哪里?

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionalOnClass.java#L39

/**
 * 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 回答

相关问题