Skip to content
Advertisement

How Spring @Autowired binds the SessionFactory object even if there is no SessionFactory instance available

I’m using Hibernate and Spring with Java-based configurations. My config file is this one:

JavaScript

Working fine. No problem with this, but when I manually try to set the sessionfactory parameter for trasactionManager, like this:

JavaScript

The IDE is showing:

JavaScript

So, I created a sessionFactory like below

JavaScript

and passed to trasactionManager It worked.

My question is how spring autowired the sessionFactory object even if there is no no sessionFactory instance present in the 1st approach?

Advertisement

Answer

You need to change the method return types from SessionFactory to HibernateTransactionManager.

This is how it should look like:

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