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/classes
和db.properties
就在那裏!哪裏錯了?
它是如此陌生,在Java中,發現在類路徑的資源,我們應該用「db.properties」,而不是「/db.properties」 – Freewind