org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createMyBean': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: No current InjectionPoint available for method 'createLogger' parameter 0

Spring JIRA | Sebastian Staack | 5 months ago
  1. 0

    When there is a prototype bean with a field annotated with {{@Autowired}} whose value is a prototype bean created in dependence of its injection point it seams that the the injection point isn't propagated. *Test setup:* {code:title=MyBeanImpl.java|borderStyle=solid} public class MyBeanImpl implements MyBean { @Autowired private Logger logger; @PostConstruct public void init() { logger.info("Hello World"); } } {code} {code:title=MyTest.java|borderStyle=solid} @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class MyTest { @Configuration static class TestConfiguration { @Bean @Scope(SCOPE_PROTOTYPE) public Logger createLogger(InjectionPoint injectionPoint) { return LogManager.getLogger(injectionPoint.getMember().getDeclaringClass()); } @Bean @Scope(SCOPE_PROTOTYPE) public MyBean createMyBean() { return new MyBeanImpl(); } } @Autowired private MyBean beanA; @Autowired private MyBean beanB; @Test public void test() { } public static void main(String[] args) { try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(TestConfiguration.class)) { ctx.getBean(MyBean.class); ctx.getBean(MyBean.class); } } } {code} If I execute the test then I get the following log: {code:title=Log output of MyTest#test()|borderStyle=solid} 16:36:53.997 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [test.MyTest]: no resource found for suffixes {-context.xml}. 16:36:54.092 [main] INFO org.springframework.test.context.support.AbstractDelegatingSmartContextLoader - AnnotationConfigContextLoader detected default configuration classes for context configuration [ContextConfigurationAttributes@255b53dc declaringClass = 'test.MyTest', classes = '{class test.MyTest$TestConfiguration}', locations = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.test.context.ContextLoader']. 16:36:54.105 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] 16:36:54.109 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute] 16:36:54.110 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext] 16:36:54.112 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Could not instantiate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource] 16:36:54.112 [main] INFO org.springframework.test.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6295d394, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@475e586c, org.springframework.test.context.support.DirtiesContextTestExecutionListener@657c8ad9]16:36:54.302 [main] INFO org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@27ae2fd0: startup date [Sat Jun 25 16:36:54 CEST 2016]; root of context hierarchy 16:36:54.757 [main] INFO test.MyBeanImpl - Hello World 16:36:54.758 [main] INFO test.MyTest - Hello World 16:36:54.764 [Thread-1] INFO org.springframework.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@27ae2fd0: startup date [Sat Jun 25 16:36:54 CEST 2016]; root of context hierarchy {code} The lines 16:36:54.757 and 16:36:54.758 in the log show that the InjectionPoint of the Logger field differs, because the injection point's member declaring class is used to instantiate the logger. I would expect that they don't differ because both times the same bean is instantiated. After a closer look I recognized that the second logger is instantiated for the test class MyTest, so I assume that the injection point isn't populated recursively. To prove my assumption I created the method {{MyTest#main()}} where I setup an {{ApplicationContext}} by hand. When I execute this method I get the following log: {code:title=Log output of MyTest#main()|borderStyle=solid} 16:56:43.372 [main] INFO org.springframework.context.annotation.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@436e852b: startup date [Sat Jun 25 16:56:43 CEST 2016]; root of context hierarchy 16:56:44.071 [main] INFO test.MyBeanImpl - Hello World 16:56:44.077 [main] INFO org.springframework.context.annotation.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@436e852b: startup date [Sat Jun 25 16:56:43 CEST 2016]; root of context hierarchy org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createMyBean': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: No current InjectionPoint available for method 'createLogger' parameter 0 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:356) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:220) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:352) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:333) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1088) at test.MyTest.main(MyTest.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.lang.IllegalStateException: No current InjectionPoint available for method 'createLogger' parameter 0 at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:830) at org.springframework.beans.factory.support.ConstructorResolver.resolvePreparedArguments(ConstructorResolver.java:784) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:415) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.resolvedCachedArgument(AutowiredAnnotationBeanPostProcessor.java:533) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.access$200(AutowiredAnnotationBeanPostProcessor.java:118) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:562) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350) ... 14 more {code} This log confirmed my assumption from above, because now there isn't a parent injection point and the thrown error state that there isn't an current injection point at all. I guess the that the method {{AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject}} must be fixed to populate the injection point of its field via {{ConstructorResolver#setCurrentInjectionPoint()}}. I have attached a maven project so that you are able to reproduce the observed behavior.

    Spring JIRA | 5 months ago | Sebastian Staack
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createMyBean': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: No current InjectionPoint available for method 'createLogger' parameter 0
  2. 0

    @Configuration class provides beans of a given qualifier but never of other

    Stack Overflow | 3 years ago | smc
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'taskDAOUsageDemonstrator': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.mb.taskmanager.TaskDAO com.mb.taskmanager.TaskDAOUsageDemonstrator.mongoTaskDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.mb.taskmanager.TaskDAO] 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), @org.springframework.beans.factory.annotation.Qualifier(value=mongo)}
  3. 0

    GitHub comment 1#18913885

    GitHub | 4 years ago | maugsburger
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'menuBarProvider' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.pmedv.core.provider.ApplicationMenuBarProviderImpl]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simulateCircuitCommand' defined in class path resource [commands.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.pmedv.blackboard.commands.SimulateCircuitCommand]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simulatorProvider' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Red5 exception creating connection

    Stack Overflow | 1 year ago | Moto Raton
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rtmpMinaConnection' defined in class path resource [red5-core.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'deadlockGuardScheduler' of bean class [org.red5.server.net.rtmp.RTMPMinaConnection]: Bean property 'deadlockGuardScheduler' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  6. 0

    Spring Boot Startup fails

    Stack Overflow | 8 months ago | Benny
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.EndpointMBeanExportAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.fasterxml.jackson.databind.ObjectMapper org.springframework.boot.actuate.autoconfigure.EndpointMBeanExportAutoConfiguration.objectMapper; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'objectMapper': Requested bean is currently in creation: Is there an unresolvable circular reference?

    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. java.lang.IllegalStateException

      No current InjectionPoint available for method 'createLogger' parameter 0

      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument()
    2. Spring Beans
      DefaultListableBeanFactory.getBean
      1. org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:830)
      2. org.springframework.beans.factory.support.ConstructorResolver.resolvePreparedArguments(ConstructorResolver.java:784)
      3. org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:415)
      4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
      5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
      6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
      7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      8. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
      9. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      10. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.resolvedCachedArgument(AutowiredAnnotationBeanPostProcessor.java:533)
      11. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.access$200(AutowiredAnnotationBeanPostProcessor.java:118)
      12. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:562)
      13. org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
      14. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
      15. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
      16. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
      17. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      18. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325)
      19. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:220)
      20. org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:352)
      21. org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:333)
      21 frames
    3. Spring Context
      AbstractApplicationContext.getBean
      1. org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1088)
      1 frame
    4. test
      MyTest.main
      1. test.MyTest.main(MyTest.java:50)
      1 frame
    5. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:498)
      4 frames
    6. IDEA
      AppMain.main
      1. com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
      1 frame