org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.persistence.EntityManager com.test.mvc.config.TestUserDetailsService.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] 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=entityManagerFactory)}

Spring JIRA | Petar Tahchiev | 3 years ago
  1. 0

    Hi guys, i'm pretty sure this bug does not belong to spring-data-jpa, but honestly I'm not sure which part of Spring to submit it to. So here's my setup: {code} project/ /module1 /module2 {code} Module1 contains a @Configuration which defines LocalContainerEntityManagerFactoryBean definition: {code} @Bean(name = { "defaultEntityManagerFactory", "entityManagerFactory" }) protected LocalContainerEntityManagerFactoryBean defaultEntityManagerFactory() throws PropertyVetoException, IOException { final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean(); entityManagerFactory.setDataSource(defaultDataSource()); entityManagerFactory.setJpaVendorAdapter(defaultJpaVendorAdapter()); entityManagerFactory.setPackagesToScan("com.test.core.model", "com.test.modules.model"); entityManagerFactory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); entityManagerFactory.setJpaProperties(defaultJpaProperties()); return entityManagerFactory; } {code} and module2 (depends on module1) contains @Configuration which tries to override some properties of the LocalContainerEntityManagerFactoryBean from module1: {code} @Bean(name = { "mvcManagerFactory", "entityManagerFactory" }) protected LocalContainerEntityManagerFactoryBean defaultEntityManagerFactory(@Qualifier("defaultEntityManagerFactory") LocalContainerEntityManagerFactoryBean entityManagerFactory) throws PropertyVetoException, IOException { entityManagerFactory.setPackagesToScan("com.test"); return entityManagerFactory; } {code} It all works good, until I define a service, which needs the LocalContainerEntityManagerFactoryBean with alias "entityManagerFactory": {code} @PersistenceContext(name = "entityManagerFactory") private EntityManager entityManager; {code} Please note I'm using the "entityManagerFactory" alias so I'm hoping the get the module2 LocalContainerEntityManagerFactoryBean. Unfortunately I get this stack trace when I start the server: {code} 17:28:38.753 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.persistence.EntityManager com.test.mvc.config.TestUserDetailsService.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] 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=entityManagerFactory)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE] {code}

    Spring JIRA | 3 years ago | Petar Tahchiev
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.persistence.EntityManager com.test.mvc.config.TestUserDetailsService.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] 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=entityManagerFactory)}
  2. 0

    Hi guys, i'm pretty sure this bug does not belong to spring-data-jpa, but honestly I'm not sure which part of Spring to submit it to. So here's my setup: {code} project/ /module1 /module2 {code} Module1 contains a @Configuration which defines LocalContainerEntityManagerFactoryBean definition: {code} @Bean(name = { "defaultEntityManagerFactory", "entityManagerFactory" }) protected LocalContainerEntityManagerFactoryBean defaultEntityManagerFactory() throws PropertyVetoException, IOException { final LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean(); entityManagerFactory.setDataSource(defaultDataSource()); entityManagerFactory.setJpaVendorAdapter(defaultJpaVendorAdapter()); entityManagerFactory.setPackagesToScan("com.test.core.model", "com.test.modules.model"); entityManagerFactory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); entityManagerFactory.setJpaProperties(defaultJpaProperties()); return entityManagerFactory; } {code} and module2 (depends on module1) contains @Configuration which tries to override some properties of the LocalContainerEntityManagerFactoryBean from module1: {code} @Bean(name = { "mvcManagerFactory", "entityManagerFactory" }) protected LocalContainerEntityManagerFactoryBean defaultEntityManagerFactory(@Qualifier("defaultEntityManagerFactory") LocalContainerEntityManagerFactoryBean entityManagerFactory) throws PropertyVetoException, IOException { entityManagerFactory.setPackagesToScan("com.test"); return entityManagerFactory; } {code} It all works good, until I define a service, which needs the LocalContainerEntityManagerFactoryBean with alias "entityManagerFactory": {code} @PersistenceContext(name = "entityManagerFactory") private EntityManager entityManager; {code} Please note I'm using the "entityManagerFactory" alias so I'm hoping the get the module2 LocalContainerEntityManagerFactoryBean. Unfortunately I get this stack trace when I start the server: {code} 17:28:38.753 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.persistence.EntityManager com.test.mvc.config.TestUserDetailsService.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] 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=entityManagerFactory)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE] {code}

    Spring JIRA | 3 years ago | Petar Tahchiev
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.persistence.EntityManager com.test.mvc.config.TestUserDetailsService.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] 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=entityManagerFactory)}
  3. 0

    Virgo Server Throwing java.lang.NoClassDefFoundError: org/json/JSONException Error while deploying a Java package

    Stack Overflow | 3 years ago | Vignesh
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxx': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxx' defined in URL [bundleentry://274.fwk22736215/META-INF/spring/bundle-context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/json/JSONException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    One-to-many relationship Hibernate Problem

    Stack Overflow | 6 years ago | cddthd
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.vaannila.vo.AuthorityVO
  6. 0

    spring security config giving error on server startup

    Stack Overflow | 5 years ago | pri_dev
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.web.access.expression.ExpressionBasedFilterInvocationSecurityMetadataSource] while setting bean property 'securityMetadataSource'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#5': Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.security.web.util.UrlMatcher]: Could not convert constructor argument value of type [java.util.LinkedHashMap] to required type [org.springframework.security.web.util.UrlMatcher]: Failed to convert value of type 'java.util.LinkedHashMap' to required type 'org.springframework.security.web.util.UrlMatcher'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.LinkedHashMap] to required type [org.springframework.security.web.util.UrlMatcher]: no matching editors or conversion strategy found

  1. qavid 2 times, last 5 months ago
  2. Bugger 1 times, last 7 months ago
  3. batwalrus76 7 times, last 1 week ago
  4. rlovtangen 1 times, last 2 weeks ago
  5. tvrmsmith 6 times, last 3 weeks ago
23 more registered users
70 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.factory.BeanCreationException

    Error creating bean with name 'testUserDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.persistence.EntityManager com.test.mvc.config.TestUserDetailsService.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManager] 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=entityManagerFactory)}

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues()
  2. Spring Beans
    DefaultListableBeanFactory.preInstantiateSingletons
    1. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    5. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    6. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    7. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    8. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    9. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    9 frames
  3. Spring Context
    AbstractApplicationContext.finishBeanFactoryInitialization
    1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    1 frame