org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyController':
Copied from the stacktrace:
BeanInstantiationException: Could not instantiate bean class [com.gestEtu.project.model.dao.CompteDAOHib]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.gestEtu.project.model.dao.CompteDAOHib.<init>()
By default, Spring will try to instantiate beans by calling a default (no-arg) constructor. The problem in your case is that the implementation of the CompteDAOHib
has a constructor with a SessionFactory
argument. By adding the @Autowired
annotation to a constructor, Spring will attempt to find a bean of matching type, SessionFactory
in your case, and provide it as a constructor argument, e.g.
@Autowired
public CompteDAOHib(SessionFactory sessionFactory) {
// ...
}
I have been getting similar error, and just want to share with you. maybe it will help someone.
If you want to use EntityManagerFactory
to get an EntityManager
, make sure that you will use:
<persistence-unit name="name" transaction-type="RESOURCE_LOCAL">
and not:
<persistence-unit name="name" transaction-type="JPA">
in persistance.xml
clean and rebuild project, it should help.