Skip to content
Advertisement

Unsatisfied dependency through ‘sessionFactory’; No qualifying bean of type ‘org.hibernate.SessionFactory’ available

I am creating a spring-mvc and hibernate webapp. I am trying to test text read in the book by creating project (hence using xml config). This type of question is asked before but I can’t get my project to work with answers offered. I get following error when I hit the end-point :

JavaScript

Here is @Configuration class

JavaScript

Here is hibernate-cfg.xml

JavaScript

DAO-

JavaScript

pom.xml

JavaScript

Advertisement

Answer

I did a workaround for this.

Instead of doing localSessionFactoryBean.getObject() to obtain hibernate session factory.

I used hibernate’s configuration class to create session factory object. The only problem was I wanted to give my own datasource. For this I created a class that implemented ConnectionProvider interface. And set property – hibernate.connection.provider_class in hibernate.cfg.xml.

And it started working.

I agree with other comments though, hbm.xmls are old way of doing things. I will learn annotations and start using them in future projects.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement