Java Tomcat服务器将不会使用筛选器启动
以下是web.xml代码:Java Tomcat服务器将不会使用筛选器启动,java,tomcat,servlet-filters,Java,Tomcat,Servlet Filters,以下是web.xml代码: 朱亚斯项目 jdbc/diadev javax.sql.DataSource 容器 小脸蛋 小脸蛋 javax.faces.webapp.FacesServlet 1. 小脸蛋 *.jsf javax.faces.PROJECT_阶段 发展 com.sun.faces.expressionFactory com.sun.el.ExpressionFactoryImpl 服务器以这种方式运行得很好,如果我删除过滤器上的注释,它将不会运行 开始并将抛出这些异常: 严重
朱亚斯项目
jdbc/diadev
javax.sql.DataSource
容器
小脸蛋
小脸蛋
javax.faces.webapp.FacesServlet
1.
小脸蛋
*.jsf
javax.faces.PROJECT_阶段
发展
com.sun.faces.expressionFactory
com.sun.el.ExpressionFactoryImpl
服务器以这种方式运行得很好,如果我删除过滤器上的注释,它将不会运行
开始并将抛出这些异常:
严重:启动期间子容器失败
java.util.concurrent.ExecutionException:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine[catalina].StandardHost[localhost]]
原因:org.apache.catalina.LifecycleException:未能启动组件[StandardEngine[catalina].StandardHost[localhost]]
原因:org.apache.catalina.LifecycleException:启动期间子容器失败
及
警告:检索容器[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Projeto_joas]]的JNDI命名上下文失败,因此未对该容器执行任何清理
javax.naming.NamingException:没有绑定到此类加载器的命名上下文
过滤器类:
package util.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.hibernate.SessionFactory;
import util.HibernateUtil;
public class ConexaoHibernateFilter implements Filter {
private SessionFactory sf;
@Override
public void init(FilterConfig arg0) throws ServletException {
this.sf = HibernateUtil.getSessionFactory();
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
FilterChain chain) throws IOException, 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);
}
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
请发布你的
util.filter.ConexaoHibernateFilter
类的内容。@luigimendoza,添加了它。我不完全确定为什么这个过滤器会导致你的应用程序部署失败,但我确信这是一个不好的做法。如果页面执行不需要事务的基本find
,该怎么办?此外,数据库事务应该在服务层(MVC的模型)中处理,而不是在过滤器(MVC的控制器)中处理。@LuiggiMendoza,我对过滤器的方法和会话工厂属性中的每一个代码都进行了注释,服务器运行了,我取消了会话工厂属性的注释错误发生了,有什么规则可以阻止过滤器具有某些属性吗?哦,我已经解决了,服务器需要知道过滤器上使用的类,所以我只需要将hibernate core-.jar复制到tomcat lib文件夹中,服务器就可以运行了。