【问题标题】:ConditionalOnClass, why JVM allow the class not in classpath in runtimeConditionalOnClass,为什么JVM在运行时允许类不在类路径中
【发布时间】:2018-04-15 17:28:30
【问题描述】:

通过学习使用spring boot,了解了spring boot ConditionalOnClass的用法和背后的逻辑,我的问题是:

  1. 为什么“由于这个注解是通过加载类字节码来解析的,所以在这里指定最终可能不在类路径上的类是安全的”。
  2. 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 {};

【问题讨论】:

    标签: spring spring-boot jvm


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 2016-07-31
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    相关资源
    最近更新 更多