我有一个java web项目,我正在使用Hibernate,JSF和Primefaces。 我有Hibernate的问题。
我遇到了这个例外:
Exception starting filter conexaoFiter
java.lang.ClassNotFoundException: com.crud.filter.ConexaoHibernateFilter
我在Web.xml
中设置了Hibernate,如下所示:
<filter>
<filter-name>conexaoFiter</filter-name>
<filter-class>com.crud.filter.ConexaoHibernateFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>conexaoFiter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
Hibernate过滤器类:
package com.crud.filter;
public class ConexaoHibernateFilter implements Filter {
private SessionFactory sf;
public void init(FilterConfig config) throws ServletException {
this.sf = HibernateUtil.getSessionFactory();
}
public void destroy() {
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException {
try {
this.sf.getCurrentSession().beginTransaction();
chain.doFilter(servletRequest, servletResponse);
this.sf.getCurrentSession().getTransaction().commit();
this.sf.getCurrentSession().close();
} catch (Throwable ex) {
try {
if (this.sf.getCurrentSession().getTransaction().isActive()) {
this.sf.getCurrentSession().getTransaction().rollback();
}
} catch (Throwable t) {
t.printStackTrace();
}
throw new ServletException(ex);
}
}
}
我该怎么办?