2011-11-14 17 views
4

在電梯的項目,我把數據庫的配置在一個叫db.properties爲什麼電梯無法找到我的「db.properties」

/src/main/resources/db.properties 
Boot.scala

和文件,我把它讀作:

val input = this.getClass.getResourceAsStream("db.properties") 
println("### input: " +input) 

val db = new java.util.Properties 
db.load(input) 

val url = db.getProperty("url") 
println("#### url:" + url) 

然後我開始SBT:

sbt prepare-web jetty-start 

控制檯打印一些錯誤:

### input: null 
21:48:55.906 [main] ERROR n.liftweb.http.provider.HTTPProvider - Failed to Boot! Your application may not run properly 
java.lang.NullPointerException: null 
    at java.util.Properties$LineReader.readLine(Properties.java:418) ~[na:1.6.0_27] 
    at java.util.Properties.load0(Properties.java:337) ~[na:1.6.0_27] 
    at java.util.Properties.load(Properties.java:325) ~[na:1.6.0_27] 
    at bootstrap.liftweb.Boot.boot(Boot.scala:21) ~[classes/:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6. 

這是奇怪的電梯找不到db.properties

我查過了target/webapp/WEB-INF/classesdb.properties就在那裏!哪裏錯了?

回答

1

您發佈應該工作的代碼 - 你可以嘗試

val input = getClass.getResourceAsStream("/db.properties")

或者你可以嘗試內置的升降道具MECCANO:如果您使用映射(=持久性框架 http://www.assembla.com/wiki/show/liftweb/Properties

那附帶電梯)你可能看看: http://www.assembla.com/spaces/liftweb/wiki/Mapper

如果一切都失敗 - 請問友好lif科技界: http://groups.google.com/group/liftweb

希望幫助 保羅

+0

它是如此陌生,在Java中,發現在類路徑的資源,我們應該用「db.properties」,而不是「/db.properties」 – Freewind

相關問題