org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null

Spring JIRA | Benoit Lacelle | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Hello, If one has a BeanPostProcessor which returns null, then the laoding of the application contact would break with an exception not clear before knowing the actual issue. Running the following test, : {code} @Configuration public static class ConfigA { @Bean public String string() { return "gogo"; } } @Configuration public static class ConfigB { @Bean public BeanPostProcessor beanPostProcessor() { return new BeanPostProcessor() { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return null; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { return null; } }; } } @Test public void testInvalidConfig() { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigA.class, ConfigB.class)) { } } {code} one would get {code} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84) at blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy.testInvalidConfig(TestApexSourceConfigAutonomy.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) {code} This seems trivial, but I got an equivalent issue while using Mockito to mock an interface, which I was unaware to be a BeanPostProcessor: Mockito returned null on postProcessBeforeInitialization, leading to this issue but the error message (and even debugging) took me a few hours to understand what was happening. Instead of "Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null", I would have expected something like "BeanPostProcessor named "beanPostProcessor" returned null for 'testApexSourceConfigAutonomy.ConfigA'" Thanks

    Spring JIRA | 3 years ago | Benoit Lacelle
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null
  2. 0

    Hello, If one has a BeanPostProcessor which returns null, then the laoding of the application contact would break with an exception not clear before knowing the actual issue. Running the following test, : {code} @Configuration public static class ConfigA { @Bean public String string() { return "gogo"; } } @Configuration public static class ConfigB { @Bean public BeanPostProcessor beanPostProcessor() { return new BeanPostProcessor() { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return null; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { return null; } }; } } @Test public void testInvalidConfig() { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigA.class, ConfigB.class)) { } } {code} one would get {code} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84) at blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy.testInvalidConfig(TestApexSourceConfigAutonomy.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) {code} This seems trivial, but I got an equivalent issue while using Mockito to mock an interface, which I was unaware to be a BeanPostProcessor: Mockito returned null on postProcessBeforeInitialization, leading to this issue but the error message (and even debugging) took me a few hours to understand what was happening. Instead of "Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null", I would have expected something like "BeanPostProcessor named "beanPostProcessor" returned null for 'testApexSourceConfigAutonomy.ConfigA'" Thanks

    Spring JIRA | 3 years ago | Benoit Lacelle
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null
  3. 0

    Basic AOP program throws BeanCurrentlyInCreationException

    Stack Overflow | 2 years ago | user3181365
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aspect' defined in Config: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [aspect.MyAspect]: Factory method 'aspect' threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'aspect': Requested bean is currently in creation: Is there an unresolvable circular reference?
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How do I use net-mgmt/unifi{2,3,4} for Ubiquity UAP-PRO?

    freebsd.org | 2 years ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'int' defined in class com.ubnt.oOOO.new: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public com.ubnt.oOOO.D.D com.ubnt.oOOO.new.int()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'class' defined in class com.ubnt.oOOO.new: Invocation of init method failed; nested exception is java.io.FileNotFoundException: /common/local/share/java/unifi/data/db/version (No such file or directory)
  6. 0

    Strange NoSuchBeanDefinitionException in Spring

    Stack Overflow | 11 months ago | delucasvb
    org.springframework.beans.factory.BeanCreationException: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Server': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private MyClass Server.myClass; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [MyClass] 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)}
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.BeanCreationException

    Error creating bean with name 'string' defined in class blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy$ConfigA: factory-bean 'testApexSourceConfigAutonomy.ConfigA' returned null

    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod()
  2. Spring Beans
    DefaultListableBeanFactory.preInstantiateSingletons
    1. org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
    2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    6. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    7. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    8. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    9. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    10. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
    10 frames
  3. Spring Context
    AnnotationConfigApplicationContext.<init>
    1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    3. org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
    3 frames
  4. blasd.apex.server
    TestApexSourceConfigAutonomy.testInvalidConfig
    1. blasd.apex.server.config.spring.autonomy.TestApexSourceConfigAutonomy.testInvalidConfig(TestApexSourceConfigAutonomy.java:118)
    1 frame
  5. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:606)
    4 frames
  6. JUnit
    ParentRunner.run
    1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    5. org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    6. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    7. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    8. org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    9. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    10. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    11. org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    12. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    13. org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    13 frames
  7. JUnit4 Runner
    JUnit4TestReference.run
    1. org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    1 frame
  8. JUnit3 Runner
    RemoteTestRunner.main
    1. org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    4. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    5. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    5 frames