title: How to Autowire SessionFactory without spring config
body: <p>I want Autowired SessionFactory, I study spring on the course and there it is done using spring config like this <a href="https://i.stack.imgur.com/cAlfK.jpg" rel="nofollow noreferrer">DataSource</a> and <a href="https://i.stack.imgur.com/rHznS.jpg" rel="nofollow noreferrer">SessionFactory</a>.
  What should I do to create this by Java class @Component or like this?</p>
  
  <p>This is my SessionFactory
   <code>private SessionFactory sessionFactory = new Configuration()
                                          .configure("hibernate.cfg.xml")
                                          .addAnnotatedClass(Customer .class)
                                          .buildSessionFactory();</code></p>
  
  <p>and <a href="https://i.stack.imgur.com/3pCoF.png" rel="nofollow noreferrer">hibernate.cfg.xml</a></p>