'No qualifying bean of type 'javax.persistence.EntityManagerFactory' available whike upgrading SpringBoot from 2.1.18.RELEASE to 2.6.2
No qualifying bean of type 'javax.persistence.EntityManagerFactory' available whike upgrading SpringBoot from 2.1.18.RELEASE to 2.6.2
@ConditionalOnProperty("spring.datasource.url")
@Configuration("databaseConfiguration")
@Service
public class DatabaseConfiguration {
/*Used both @Autowired and @PersistenceUnit but still giving same exception*/
@PersistenceUnit
private EntityManagerFactory entityManagerFactory;
@Autowired
ApplicationContext context;
@PostConstruct
public void initSessionFactory() {
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry()
.getService(EventListenerRegistry.class);
registry.getEventListenerGroup(EventType.PERSIST).prependListener(new EntityListener());
registry.getEventListenerGroup(EventType.SAVE).prependListener(new EntityListener());
registry.getEventListenerGroup(EventType.SAVE_UPDATE).prependListener(new EntityListener());
registry.getEventListenerGroup(EventType.PERSIST_ONFLUSH).prependListener(new EntityListener());
ConfigurableListableBeanFactory beanFactory =
((ConfigurableApplicationContext) context).getBeanFactory();
beanFactory.registerSingleton("sessionFactory",
sessionFactory);
}
}
Could someone help me to resolve this issue.
Thanks.
Solution 1:[1]
Are you sure that you have an implementation of that interface in your project? If you're using Spring Boot then maybe this Maven dependency could help:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
For configuration have a look at some tutorial, e.g. https://www.bezkoder.com/jpa-entitymanager-spring-boot/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | S. Doe |