我在 JSF、spring、Hibernate 和 Spring security 中有一个应用程序,hibernate 层和数据库之间的交互进展顺利,一旦 spring 安全层查询不会呈现任何内容。
有什么解决办法吗?
我正在从休眠配置文件创建我的 SessionFactory
web.xml 中的过滤器:.....................
!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
.....................
休眠会话工厂创建类:
…………………………………………………………………………………………………………………………
package Util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
try {
Configuration configuration = new AnnotationConfiguration();;
configuration.configure();
ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(sr);
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
@Transactional
public class stufImp implements stufDAO , Serializable {
private SessionFactory sf = HibernateUtil.getSessionFactory();
Session session ;
public stufImp() {
}
@Override
public List<Stuf> getAllstufs() {
session=sf.getCurrentSession();
session.beginTransaction();
List<Stuf> stufs= session.createQuery("from Stuf").list();
session.getTransaction().commit();
System.out.println("getting All Stufs");
return stufs;
}
.....................