org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException

Spring JIRA | Andreas Thaler | 4 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    Assumed you have a BeanFactory designed for extension (for example using lookup-method) {code} public abstract class MyFactory implements FactoryBean{ ... } {code} configured as abstract bean {code} <bean id="myFactory" abstract="true" class="MyFactory"> {code} then a call to {code}ApplicationContext.getBeansWithAnnotation(..){code} will try to instantiate the class, which is against the contract for the abstract flag of the configuration (Specify "true" to tell the bean factory to not try to instantiate that particular bean in any case.) As the class is an abstract class the call will fail with: {code} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:767) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:698) at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:578) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAnnotationOnBean(DefaultListableBeanFactory.java:464) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansWithAnnotation(DefaultListableBeanFactory.java:449) at org.springframework.context.support.AbstractApplicationContext.getBeansWithAnnotation(AbstractApplicationContext.java:1182) at ... {code} Same scenario will work fine if class is not implementing FactoryBean, so it seems that for the special case of a FactoryBean the abstract flag is not repected.

    Spring JIRA | 4 years ago | Andreas Thaler
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException
  2. 0

    Assumed you have a BeanFactory designed for extension (for example using lookup-method) {code} public abstract class MyFactory implements FactoryBean{ ... } {code} configured as abstract bean {code} <bean id="myFactory" abstract="true" class="MyFactory"> {code} then a call to {code}ApplicationContext.getBeansWithAnnotation(..){code} will try to instantiate the class, which is against the contract for the abstract flag of the configuration (Specify "true" to tell the bean factory to not try to instantiate that particular bean in any case.) As the class is an abstract class the call will fail with: {code} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:767) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:698) at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:578) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAnnotationOnBean(DefaultListableBeanFactory.java:464) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansWithAnnotation(DefaultListableBeanFactory.java:449) at org.springframework.context.support.AbstractApplicationContext.getBeansWithAnnotation(AbstractApplicationContext.java:1182) at ... {code} Same scenario will work fine if class is not implementing FactoryBean, so it seems that for the special case of a FactoryBean the abstract flag is not repected.

    Spring JIRA | 4 years ago | Andreas Thaler
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException
  3. 0

    GitHub comment 711#164033053

    GitHub | 1 year ago | timwebster9
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hystrixDemoApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.oauth2.client.OAuth2RestTemplate uk.co.aquilauk.HystrixDemoApplication.restTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.oauth2.client.OAuth2RestTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring BeanCreationException : Bean instantiation via factory method failed; nested exception

    Stack Overflow | 11 months ago | ValentinD
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nickeedApplication': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.nickeed.ServiceInterface.UserServiceInterface com.nickeed.NickeedApplication.userServiceInterface; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.nickeed.repository.UserRepository com.nickeed.ServiceImpl.UserServiceImpl.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not an managed type: class com.nickeed.model.User

    1 unregistered visitors

    Root Cause Analysis

    1. org.springframework.beans.factory.BeanCreationException

      Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException

      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean()
    2. Spring Beans
      DefaultListableBeanFactory.getBeansWithAnnotation
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
      3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:767)
      4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:698)
      5. org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:578)
      6. org.springframework.beans.factory.support.DefaultListableBeanFactory.findAnnotationOnBean(DefaultListableBeanFactory.java:464)
      7. org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansWithAnnotation(DefaultListableBeanFactory.java:449)
      7 frames
    3. Spring Context
      AbstractApplicationContext.getBeansWithAnnotation
      1. org.springframework.context.support.AbstractApplicationContext.getBeansWithAnnotation(AbstractApplicationContext.java:1182)
      1 frame