【问题标题】:configuring Hibernate with Spring MVC Template in STS在 STS 中使用 Spring MVC 模板配置 Hibernate
【发布时间】:2012-12-09 13:43:22
【问题描述】:

我使用 STS 并创建了 MVC 模板项目。我想使用hibernate,但我不知道把hibernate.cfg.xml放在哪里。在默认项目中,我只是将它放在 src/ 文件夹中。

    static {

        try {

            // Create the SessionFactory from hibernate.cfg.xml
            //AnnotationConfiguration
            sessionFactory = new Configuration().configure().buildSessionFactory();

        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {

        return sessionFactory;

    }
}

我知道我可以像这样严格添加 Hibernate.cfg.xml 的路径:

sessionFactory = new Configuration().configure("XXX").buildSessionFactory();

其中 XXX 是 hibernate.cfg.xml 的路径。如果我愿意,我应该把 hibernate.cfg.xml 放在哪里 使用“/hibernate.cfg.xml”之类的路径?谢谢!

【问题讨论】:

    标签: hibernate spring-mvc configure hibernate.cfg.xml


    【解决方案1】:

    您必须将默认包放入源目录(无论其名称如何)中,以便 Eclipse 在编译时将其复制到目标文件夹,从而在执行应用程序时在类路径的根目录中可用。

    【讨论】:

      猜你喜欢
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      相关资源
      最近更新 更多