'No qualifying bean of type 'javax.persistence.EntityManager' available: expected at least 1 bean which qualifies as autowire candidate
I have this problem...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
I don't usually boot. these are configurations:
@Configuration
@EnableTransactionManagement
public class SpringOrmConfig {
private final DataSource dataSource;
@Autowired
public SpringOrmConfig(@Qualifier("dataSource") DataSource dataSource) {
this.dataSource = dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean factoryBean(@Autowired Properties jpaProperties) {
LocalContainerEntityManagerFactoryBean emFactoryBean = new LocalContainerEntityManagerFactoryBean();
emFactoryBean.setDataSource(dataSource);
emFactoryBean.setPersistenceUnitName("jpa-unit");
emFactoryBean.setPersistenceUnitName("localContainerEntityManagerFactoryBean");
emFactoryBean.setPersistenceUnitName("factoryBean");
emFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
emFactoryBean.setPackagesToScan("my.package");
emFactoryBean.setJpaProperties(jpaProperties);
return emFactoryBean;
}
...
The problem occurs in this class
@Repository
public class MyRepoSpringOrmImpl extends AbstractSpringOrm<Group> implements MyRepo {
@Autowired
protected MyRepoSpringOrmImpl(EntityManager em) {
super(em, My.class);
}
...
configuration
@ComponentScan("my.package")
@PropertySource("classpath:db_config.properties")
@EnableWebMvc
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableTransactionManagement
public class ApplicationConfig implements WebMvcConfigurer {
@Value("${driver}")
String driver;
@Value("${url}")
String url;
@Value("${login}")
String login;
@Value("${password}")
String password;
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClass(driver);
dataSource.setJdbcUrl(url);
dataSource.setUser(login);
dataSource.setPassword(password);
return dataSource;
}
I do not understand what's the matter... Help please
p.s. I deliberately didn't use Spring Boot because it's not allowed in my project
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
