org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue]

Spring JIRA | Marty Kube | 6 years ago
  1. 0

    Cannot @Autowire to inject an instance of java.util.concurrent.BlockingQueue. The above forum has a post from 2009. I was able to reproduce this problem and have attached a minimal example. This works with XML based bean configuration but not with the annotation @Autowired. AppComponent.java: {code} package com.example; import java.util.concurrent.BlockingQueue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; @Component public class AppComponent { @Autowired public BlockingQueue queue; public static void main(String[] args) { new ClassPathXmlApplicationContext("com/example/context.xml").getBean(AppComponent.class); } } {code} Config.java: {code} package com.example; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class Config { @Bean public BlockingQueue blockingQueue() { return new LinkedBlockingQueue(); } } {code} context.xml: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <context:component-scan base-package="com.example" /> </beans> {code} The runtime error is: {code} Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.example.AppComponent.main(AppComponent.java:17) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282) ... 13 more Caused by: org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:740) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474) ... 15 more {code}

    Spring JIRA | 6 years ago | Marty Kube
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue]
  2. 0

    Cannot @Autowire to inject an instance of java.util.concurrent.BlockingQueue. The above forum has a post from 2009. I was able to reproduce this problem and have attached a minimal example. This works with XML based bean configuration but not with the annotation @Autowired. AppComponent.java: {code} package com.example; import java.util.concurrent.BlockingQueue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Component; @Component public class AppComponent { @Autowired public BlockingQueue queue; public static void main(String[] args) { new ClassPathXmlApplicationContext("com/example/context.xml").getBean(AppComponent.class); } } {code} Config.java: {code} package com.example; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class Config { @Bean public BlockingQueue blockingQueue() { return new LinkedBlockingQueue(); } } {code} context.xml: {code:xml} <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <context:component-scan base-package="com.example" /> </beans> {code} The runtime error is: {code} Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.example.AppComponent.main(AppComponent.java:17) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282) ... 13 more Caused by: org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:740) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474) ... 15 more {code}

    Spring JIRA | 6 years ago | Marty Kube
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appComponent': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public java.util.concurrent.BlockingQueue com.example.AppComponent.queue; nested exception is org.springframework.beans.FatalBeanException: No element type declared for collection [java.util.concurrent.BlockingQueue]
  3. 0

    Getting error while dynamically providing input,output path

    Stack Overflow | 8 months ago | Varun Maurya
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'itemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemReader' defined in class path resource [spring/config/process-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy11 implementing org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.item.file.MultiResourceItemReader] for property 'multiReader'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy11 implementing org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.item.file.MultiResourceItemReader] for property 'multiReader': no matching editors or conversion strategy found
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Issues in serializers config

    GitHub | 3 years ago | dsukhoroslov
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hzInstance': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static com.hazelcast.core.HazelcastInstance com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.config.Config)] threw exception; nested exception is com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.NoSuchMethodException: com.hazelcast.nio.serialization.PortableSerializer.<init>()
  6. 0

    'circle' defined in class path resource [Spring.xml]: Initialization of bean failed; nested exception is java.lang.IllegalAccessError

    Stack Overflow | 3 years ago | user2681868
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'circle' defined in class path resource [Spring.xml]: Initialization of bean failed; nested exception is java.lang.IllegalAccessError

  1. batwalrus76 7 times, last 1 week ago
  2. rlovtangen 1 times, last 2 weeks ago
  3. tvrmsmith 6 times, last 3 weeks ago
  4. kjhdofjosvs 1 times, last 1 month ago
  5. Andreas Häber 2 times, last 1 month ago
23 more registered users
72 unregistered visitors
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.FatalBeanException

    No element type declared for collection [java.util.concurrent.BlockingQueue]

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency()
  2. Spring Beans
    DefaultListableBeanFactory.preInstantiateSingletons
    1. org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:740)
    2. org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
    3. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
    4. org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    5. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
    6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    9. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    10. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    11. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    12. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    13. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    13 frames
  3. Spring Context
    ClassPathXmlApplicationContext.<init>
    1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    3. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    4. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    4 frames
  4. com.example
    AppComponent.main
    1. com.example.AppComponent.main(AppComponent.java:17)
    1 frame