Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse OpenShift上的JBoss服务器上找不到hibernate.cfg.xml_Eclipse_Hibernate_Jboss_Openshift - Fatal编程技术网

Eclipse OpenShift上的JBoss服务器上找不到hibernate.cfg.xml

Eclipse OpenShift上的JBoss服务器上找不到hibernate.cfg.xml,eclipse,hibernate,jboss,openshift,Eclipse,Hibernate,Jboss,Openshift,朋友们正在尝试通过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.cf

朋友们正在尝试通过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 2013/01/03 14:02:59296错误[com.wavetech_st.util.HibernateUtil](MSC服务线程1-4)Falha na criação do objeto会话工厂:org.hibernate.hibernate异常:hibernate.cfg.xml未找到 2013/01/03 14:02:59298错误[org.apache.catalina.core.ContainerBase.[jboss.web].[default host].[testehome]](MSC服务线程1-4)启动筛选器conexaoFilter时出现异常:java.lang.ExceptionInInitializeError 在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] 运行(Thread.java:722)[rt.jar:1.7.0_09-icedtea] 原因:org.hibernate.HibernateException:resources/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中创建这个应用程序。我已经在本地服务器JBoss7.1上对它进行了测试,它可以正常工作。但是,当我尝试远程时,会出现错误。在部署到OpenShift之前,我将hibernate.cfg文件设置为数据源:

java:jboss/datasources/MysqlDS

这是我的目录结构:

这是我的网络过滤器:

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() {} } 包com.wavetech_st.web.filter; 导入java.io.IOException; 导入javax.servlet.*; 导入org.hibernate.SessionFactory; 导入com.wavetech_st.util.HibernateUtil; 公共类ConexaoHibernateFilter实现过滤器{ 私人会话工厂sf; @凌驾 public void init(FilterConfig config)抛出ServletException{//executado quando o aplicativo web e colocado no ar this.sf=HibernateUtil.getSessionFactory(); } @凌驾 public void doFilter(ServletRequest ServletRequest、ServletResponse ServletResponse、FilterChain chain)抛出IOException、ServletException{ 试一试{ this.sf.getCurrentSession().beginTransaction(); doFilter(servletRequest,servletResponse); this.sf.getCurrentSession().getTransaction().commit(); this.sf.getCurrentSession().close(); }捕获(可丢弃的ex){ 试一试{ if(this.sf.getCurrentSession().getTransaction().isActive()) this.sf.getCurrentSession().getTransaction().rollback(); }捕获(可丢弃的t){ t、 printStackTrace(); } 抛出新的ServletException(ex); } } @凌驾 public void destroy(){} }
这是我的HibernateUtil:
包com.wavetech_st.util;
导入org.apache.log4j.Logger;
导入org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入org.hibernate.service.ServiceRegistry;
导入org.hibernate.service.ServiceRegistryBuilder;
公共类HibernateUtil{
静态最终记录器=Logger.getLogger(HibernateUtil.class);
私有静态最终SessionFactory SessionFactory=buildSessionFactory();
私有静态ServiceRegistry ServiceRegistry;
私有静态SessionFactory buildSessionFactory(){
试一试{
Configuration cfg=new Configuration().configure(“hibernate.cfg.xml”);
serviceRegistry=new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
返回cfg.buildSessionFactory(serviceRegistry);
}捕获(可丢弃的e){
记录器错误(“Falha na criação do objeto会话工厂:”+e);
抛出新异常初始化错误(e);
}
}
公共静态SessionFactory getSessionFactory(){
返回工厂;
}
}


请帮忙:-/

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


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

谢谢你,伙计,我在jBoss Openshift和Mybatis中也遇到了同样的问题,但是你的回答帮助了我,我附上了一张图片,其中我把Mybatis配置文件放在了与hiberna类似的文件中 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() {} }
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;
    }
}