Java 获取异常:没有绑定到线程的Hibernate会话。我正在使用SpringMVC

Java 获取异常:没有绑定到线程的Hibernate会话。我正在使用SpringMVC,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,} 我的SpringServlet配置看起来像 package com.ibs.dao; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import com.ibs.entity.LoginEntity; @Repository public

}

我的SpringServlet配置看起来像

package com.ibs.dao;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ibs.entity.LoginEntity;
@Repository
public class LoginDaoImpl implements LoginDaoInterface {

@Autowired
SessionFactory sessionFactory;


public boolean validateLogin(LoginEntity loginEntity)
{

    String eid=loginEntity.getEid();
    LoginEntity log=(LoginEntity)sessionFactory.getCurrentSession().load(LoginEntity.class, eid);

    if(log.getPassword().equals(loginEntity.getPassword()))
    {
        return true;
    }
    else
    {
        return false;
    }


}

将以下行从
LoginDaoImpl

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
    org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:700)
    com.ibs.dao.LoginDaoImpl.validateLogin(LoginDaoImpl.java:20)
至:

 LoginEntity log=(LoginEntity)sessionFactory.getCurrentSession().load(LoginEntity.class, eid);

或者:在hibernate属性中添加key
hibernate.current\u session\u context\u class
和value
Thread

您是否有一些声明事务管理器的配置部分?查看此帖子-谢谢,现在我配置了事务管理器。但是出现了一个新错误->创建名为“loginController”的bean时出错:自动连线依赖项的注入失败;可能的原因是什么?Sharat,更新您的问题,添加您所做的更改,并完成错误的stacktrace。谢谢。现在一切都好了。
 LoginEntity log=(LoginEntity)sessionFactory.getCurrentSession().load(LoginEntity.class, eid);
 LoginEntity log=(LoginEntity)sessionFactory.openSession().load(LoginEntity.class, eid);