org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: <A> nested exception is java.io.FileNotFoundException: class path resource path/to/B.class] cannot be opened because it does not exist

Spring JIRA | Olaf Otto | 2 years ago
  1. 0

    During the resolution of AnnotationMetadata, the following issue arises if a class A with classloader Ca and a super class B with classloaderCb is processed in the ConfigurationClassParser (provided Cb is not the parent of Ca, for instance when using imported types in OSGi) {code} org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: <A> nested exception is java.io.FileNotFoundException: class path resource path/to/B.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:291) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:242) {code} Here, the parsing of the super class is unaware of the class loader of the extending class: {code:java} String superclass = metadata.getSuperClassName(); ... MetadataReader reader = this.metadataReaderFactory.getMetadataReader(superclass); return reader.getAnnotationMetadata(); {code} However, this also is an architectural issue, as it is an explicit design goal of the ClassMetadata not to load the type (resulting in the defining class loader being ignored), as state in the ClassMetaData JavaDoc: {code:java} * in a form that does not require that class to be loaded yet. {code} As there is no way to determine the defining class loader without loading the class, I do suggest to drop this design goal as it directly contradicts proper treatment of class loading semantics.

    Spring JIRA | 2 years ago | Olaf Otto
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: <A> nested exception is java.io.FileNotFoundException: class path resource path/to/B.class] cannot be opened because it does not exist
  2. 0

    During the resolution of AnnotationMetadata, the following issue arises if a class A with classloader Ca and a super class B with classloaderCb is processed in the ConfigurationClassParser (provided Cb is not the parent of Ca, for instance when using imported types in OSGi) {code} org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: <A> nested exception is java.io.FileNotFoundException: class path resource path/to/B.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:291) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:242) {code} Here, the parsing of the super class is unaware of the class loader of the extending class: {code:java} String superclass = metadata.getSuperClassName(); ... MetadataReader reader = this.metadataReaderFactory.getMetadataReader(superclass); return reader.getAnnotationMetadata(); {code} However, this also is an architectural issue, as it is an explicit design goal of the ClassMetadata not to load the type (resulting in the defining class loader being ignored), as state in the ClassMetaData JavaDoc: {code:java} * in a form that does not require that class to be loaded yet. {code} As there is no way to determine the defining class loader without loading the class, I do suggest to drop this design goal as it directly contradicts proper treatment of class loading semantics.

    Spring JIRA | 2 years ago | Olaf Otto
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: <A> nested exception is java.io.FileNotFoundException: class path resource path/to/B.class] cannot be opened because it does not exist
  3. 0

    @PropertySource in a Jar for an external file on the classpath

    Stack Overflow | 2 years ago | sh1ftst0rm
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.example.stc.Config; nested exception is java.io.FileNotFoundException: class path resource [stc.properties] cannot be opened because it does not exist
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    option `--auto-export-maven-dependencies` doesn't

    GitHub | 2 years ago | CeylonMigrationBot
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.vasileff.csmpetstore.config.AppConfig; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
  6. 0

    option `--auto-export-maven-dependencies` doesn't

    GitHub | 2 years ago | jvasileff
    org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.vasileff.csmpetstore.config.AppConfig; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.beans.factory.BeanDefinitionStoreException

      Failed to load bean class: <A> nested exception is java.io.FileNotFoundException: class path resource path/to/B.class] cannot be opened because it does not exist

      at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions()
    2. Spring Context
      ConfigurationClassPostProcessor.postProcessBeanFactory
      1. org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:291)
      2. org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:242)
      2 frames