【问题标题】:hibernate.cfg.xml not found on the JBoss server on OpenShift在 OpenShift 上的 JBoss 服务器上找不到 hibernate.cfg.xml
【发布时间】:2012-12-18 05:54:08
【问题描述】:

朋友们正在尝试通过休眠 orm 在 openshift 中连接我的应用程序。 但部署失败。您可以查看服务器日志中的错误消息:

2013/01/03 14:02:59,296 错误 [com.wavetech_st.util.HibernateUtil](MSC 服务线程 1-4)Falha na criação do object SessionFactory:org.hibernate.HibernateException:hibernate.cfg.xml not found 2013/01/03 14:02:59,298 错误 [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/testehome]](MSC 服务线程 1-4)异常启动过滤器conexaoFilter: java.lang.ExceptionInInitializerError 在 com.wavetech_st.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:26) [类:] 在 com.wavetech_st.util.HibernateUtil.(HibernateUtil.java:12) [类:] 在 com.wavetech_st.web.filter.ConexaoHibernateFilter.init(ConexaoHibernateFilter.java:31) [类:] 在 org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.10.Final.jar:] 在 org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.10.Final.jar:] 在 org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.10.Final.jar:] 在 org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final] 在 org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) 在 org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09-icedtea] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09-icedtea] 在 java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09-icedtea] 引起:org.hibernate.HibernateException:找不到资源/hibernate.cfg.xml 在 org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173) [hibernate-core-4.1.1.Final.jar:4.1.1.Final] 在 org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1943) [hibernate-core-4.1.1.Final.jar:4.1.1.Final] 在 org.hibernate.cfg.Configuration.configure(Configuration.java:1924) [hibernate-core-4.1.1.Final.jar:4.1.1.Final] 在 com.wavetech_st.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:19) [类:] ... 11 更多

我正在 Eclipse 中创建这个应用程序。我已经在本地服务器 JBoss 7.1 上对其进行了测试,并且可以正常工作。但是,当我尝试远程时会出现错误。在部署到 OpenShift 之前,我将文件 hibernate.cfg 设置为数据源:

<property name="connection.datasource">java:jboss/datasources/MysqlDS</property>

这是我的目录结构:

这是我的网络过滤器:

包 com.wavetech_st.web.filter; 导入 java.io.IOException; 导入 javax.servlet.*; 导入 org.hibernate.SessionFactory; 导入 com.wavetech_st.util.HibernateUtil; 公共类 ConexaoHibernateFilter 实现过滤器 { 私人 SessionFactory sf; @覆盖 public void init(FilterConfig config) throws ServletException {// executado quando o aplicativo web e colocado no ar this.sf = HibernateUtil.getSessionFactory(); } @覆盖 公共无效doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain链)抛出IOException,ServletException { 尝试 { this.sf.getCurrentSession().beginTransaction(); chain.doFilter(servletRequest, servletResponse); this.sf.getCurrentSession().getTransaction().commit(); this.sf.getCurrentSession().close(); } 捕捉(可投掷的前){ 尝试 { if(this.sf.getCurrentSession().getTransaction().isActive()) this.sf.getCurrentSession().getTransaction().rollback(); } 捕捉(可投掷的 t){ t.printStackTrace(); } 抛出新的 ServletException(ex); } } @覆盖 公共无效销毁(){} }
This is my HibernateUtil:

<pre>

package com.wavetech_st.util;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {

    static final Logger logger = Logger.getLogger(HibernateUtil.class);
    private static final SessionFactory sessionFactory  = buildSessionFactory();
    private static ServiceRegistry      serviceRegistry;

    private static SessionFactory buildSessionFactory() {

        try {

            Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
            serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();

            return cfg.buildSessionFactory(serviceRegistry);
        } catch (Throwable e) {

            logger.error("Falha na criação do objeto SessionFactory: " + e);
            throw new ExceptionInInitializerError(e);

        }
    }

    public static SessionFactory getSessionFactory() {

        return sessionFactory;
    }
}

请帮忙:-/

【问题讨论】:

    标签: eclipse hibernate jboss openshift


    【解决方案1】:

    我按照这些人的提示解决了我的问题:

    stackoverflow.com/questions/4934330/org-hibernate-hibernateexception-hibernate-cfg-xml-not-found shaunabram.com/tag/hibernate/

    我的问题是将 hibernate.cfg.xml 文件放在错误的位置。如何使用 Maven 我不应该放在根目录,而是放在 src 目录根资源。

    【讨论】:

      【解决方案2】:

      谢谢老兄,我在 jBoss-Openshift 和 Mybatis 中遇到了同样的问题,但是你的回答对我有帮助,我附上了一张图片,我把 Mybatis 配置文件放在了与 hibernate 类似的文件中

      【讨论】:

        猜你喜欢
        • 2012-07-31
        • 1970-01-01
        • 2015-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多