Friends'm试图通过hibernate orm在openshift中连接我的应用程序。 但部署失败了。您可以在服务器日志中查看错误消息:
2013/01/03 14:02:59,296 ERROR [com.wavetech_st.util.HibernateUtil] (MSC service thread 1-4) Falha na criação do objeto SessionFactory: org.hibernate.HibernateException: hibernate.cfg.xml not found 2013/01/03 14:02:59,298 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/testehome]] (MSC service thread 1-4) Exception starting filter conexaoFilter: java.lang.ExceptionInInitializerError at com.wavetech_st.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:26) [classes:] at com.wavetech_st.util.HibernateUtil.(HibernateUtil.java:12) [classes:] at com.wavetech_st.web.filter.ConexaoHibernateFilter.init(ConexaoHibernateFilter.java:31) [classes:] at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.10.Final.jar:] at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.10.Final.jar:] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.10.Final.jar:] at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09-icedtea] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09-icedtea] at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09-icedtea] Caused by: org.hibernate.HibernateException: resources/hibernate.cfg.xml not found at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173) [hibernate-core-4.1.1.Final.jar:4.1.1.Final] at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1943) [hibernate-core-4.1.1.Final.jar:4.1.1.Final] at org.hibernate.cfg.Configuration.configure(Configuration.java:1924) [hibernate-core-4.1.1.Final.jar:4.1.1.Final] at com.wavetech_st.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:19) [classes:] ... 11 more
我正在Eclipse中创建这个应用程序。我已经在本地服务器JBoss 7.1上测试了它,它的工作原理。但是,当我尝试远程时给出错误。在部署到OpenShift之前,我将文件hibernate.cfg设置为数据源:
<property name="connection.datasource">java:jboss/datasources/MysqlDS</property>
<property name="connection.datasource">java:jboss/datasources/MysqlDS</property>
这是我的目录结构:
这是我的WebFilter:
package com.wavetech_st.web.filter; import java.io.IOException; import javax.servlet.*; import org.hibernate.SessionFactory; import com.wavetech_st.util.HibernateUtil; public class ConexaoHibernateFilter implements Filter { private SessionFactory sf; @Override public void init(FilterConfig config) throws ServletException {// executado quando o aplicativo web e colocado no ar 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() {} }
请帮助: - /
答案 0 :(得分:1)
我按照这些人的暗示解决了我的问题:
stackoverflow.com/questions/4934330/org-hibernate-hibernateexception-hibernate-cfg-xml-not-found shaunabram.com/tag/hibernate/
我的问题是将hibernate.cfg.xml文件放在错误的位置。如何使用Maven我不应该放在根目录中,而是放在src目录中的根目录。
答案 1 :(得分:0)
谢谢你的队友,我在jBoss-Openshift和Mybatis中遇到了同样的问题,但是你的回答帮助了我,我附上了一张图片,其中我把Mybatis配置文件与hibernate类似的文件