2013-03-08 80 views
0

我已使用我的user.properties文件訪問存儲在WEB-INF文件夾中的數據庫。它在通過GGTS(Groovy Grail Tool Suite)運行時正常工作。在Apache Tomcat上部署時無法訪問屬性文件

我的DataSource

使用

Properties prop = new Properties(); 
prop.load(DataSource.class.getClassLoader().getResourceAsStream("user.properties")); 

當我運行它作爲獨立

其工作但在創建它的戰爭文件,並將其部署到Tomcat服務器它不工作。

我的user.properties位於WEB-INF文件夾中。

顯示錯誤adavance

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException 

感謝。請幫助

回答

2

您正在使用類加載器加載文件。但是在類路徑中,WEB-INF而不是WEB-INF/classes位於類路徑中,以及WEB-INF/lib目錄中的每個jar。

+0

爵士WEB-INF/classes文件夾,請立即告訴我,我有什麼關係? – Rahul 2013-03-08 18:01:03

+0

將文件移動到WEB-INF/classes,以便它位於類路徑中。 – 2013-03-08 18:02:24

+0

先生,謝謝thanx很多你是偉大的....如果你有任何可以幫助我學習tomcat的博客,請參閱我新的感謝。 – Rahul 2013-03-08 18:16:03

2

那是因爲,user.properties不在Web應用程序類路徑中。

解決方案

  • 移動的user.properties,當你建立戰爭
相關問題