2012-12-09 36 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在編譯時將其複製到目標文件夾,這使得在執行應用程序時可以在類路徑的根目錄中使用它。

相關問題