SessionFactory injection isn't working

荒凉一梦 提交于 2019-12-07 03:32:29

inject like following, it'll work fine

@Autowired
@Qualifier("sessionFactory")
private SessionFactory sessionFactory;

public Session getSession() {
    return sessionFactory.getCurrentSession();
}

Hope to help you:)

In some Spring versions, sub folders are not scanned. Either move your class in the package com.csu.library.mvc or add the package com.csu.library.mvc.hibernate in the scanned packages and give it a try.

You'll want to use the org.springframework.beans.factory.annotation.Autowired annotation instead of javax.inject.Inject.

@Autowired
private SessionFactory sessionFactory;

Note that only looks for annotations on beans in the same application context it is defined in. This means that, if you put in a WebApplicationContext for a DispatcherServlet, it only checks for @Autowired beans in your controllers, and not your services.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!