org.springframework.beans.factory.BeanCreationException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

Check Servers Launch Configuration in Eclipse. See the details below.

tip

Spring expects that the EntityManagerFactory has to be called "entityManagerFactory". It uses convention over configuration to make it easier to use.

tip

Add slf4j dependency to your pom.xml

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • 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}
    via by Petar Tahchiev,
  • 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}
    via by Petar Tahchiev,
  • One-to-many relationship Hibernate Problem
    via Stack Overflow by cddthd
    ,
  • Remove hibernate.cache from cribbed app
    via Stack Overflow by user3289703
    ,
  • [Neo4j] Spring Data Graph in an OSGi environment
    via by Jean-Pierre Bergamin,
  • [SPR-4512] NPE in AspectJ - Spring JIRA
    via by Unknown author,
    • 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]

    Users with the same issue

    Unknown visitor2 times, last one,
    Unknown visitor1 times, last one,
    qavid
    2 times, last one,
    Bugger
    1 times, last one,
    Unknown visitor1 times, last one,
    286 more bugmates