JAVAWarningFramework ErrorMay 21, 2026

Framework Error

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService': Cannot create inner bean 'myDAO' of type [com.example.MyDAO] while setting bean property 'myDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDAO': Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' found in the application context

What This Error Means

This error occurs when the Spring Framework is unable to create a bean (an object managed by the Spring IoC container) due to a dependency issue. In this case, it's a problem with the bean's dependency injection, specifically with the EntityManagerFactory.

Why It Happens

This error typically happens when there's a mismatch between the expected bean definitions in the application context and the actual definitions. It can also occur when the required dependencies, in this case, the EntityManagerFactory, are not properly registered or configured in the application context.

How to Fix It

  1. 1To fix this error, you need to ensure that the EntityManagerFactory is correctly registered in the application context. This can be done by adding the necessary configuration, such as the @EnableJpaRepositories annotation, or by manually creating a bean for the EntityManagerFactory using the @Bean annotation.

Example Code Solution

❌ Before (problematic code)
Java
@SpringBootApplication
deep public class MyApplication {
	private MyDAO myDAO;

	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);
	}
}

@Repository
public class MyDAO {
	// ...
}
✅ After (fixed code)
Java
@SpringBootApplication
deep public class MyApplication {
	
	public static void main(String[] args) {
		SpringApplication.run(MyApplication.class, args);
	}
}

@Configuration
public class DataConfig {
	
	@Bean
	public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
		LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();
		bean.setDataSource(dataSource());
		bean.setPackagesToScan("com.example.entity");
		return bean;
	}

	@Bean
	public PlatformTransactionManager transactionManager() {
		JpaTransactionManager transactionManager = new JpaTransactionManager();
		transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
		return transactionManager;
	}
}

@EnableJpaRepositories
public class RepositoryConfig {
	
	// ...
}

Fix for org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService': Cannot create inner bean 'myDAO' of type [com.example.MyDAO] while setting bean property 'myDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDAO': Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManagerFactory' found in the application context

Related JAVA Errors

Related JAVA Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error