2012-12-09 38 views
0

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

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”像路径?谢谢!

回答

0

您必须将其放入源目录中的默认包(不管它的名称是什么),以便Eclipse在编译时将其复制到目标文件夹,这使得在执行应用程序时可以在类路径的根目录中使用它。

相关问题