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

时间:2017-11-03 03:25:05

标签: spring spring-boot jvm

经过研究和使用spring boot,我了解弹簧启动ConditionalOnClass背后的用法和逻辑,我的问题是:

  1. 为什么"由于这个注释是通过加载类字节码来解析的,因此可以安全地在这里指定最终可能不在类路径上的类"。
  2. JVM规范在哪里与此相关?
  3. 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 {};