为什么 lift 找不到我的“db.properties”
在一个 lift 项目中,我将数据库配置放在一个名为 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.
奇怪的 lift 找不到 db.properties
!
我检查了 target/webapp/WEB-INF/classes
,并且 db.properties
就在那里!哪里错了?
In a lift project, I put the db configurations in a file called db.properties
/src/main/resources/db.properties
And in my Boot.scala
, I read it as:
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)
Then I start sbt:
sbt prepare-web jetty-start
The console prints some errors:
### 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.
It's strange lift can't find the db.properties
!
I've checked target/webapp/WEB-INF/classes
, and db.properties
is there! Where is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的代码应该可以工作 - 您可以尝试
val input = getClass.getResourceAsStream("/db.properties")
或者您可以尝试内置的 Lift Props meccano:
http://www.assembla.com/wiki/show/liftweb/Properties
如果您使用 Mapper(= Lift 附带的持久性框架),您可能会看看:
http://www.assembla.com/spaces/liftweb/wiki/Mapper
如果一切都失败了 - 询问友好的电梯社区:
http://groups.google.com/group/liftweb
希望有帮助
保罗
The code you posted should work - you might try
val input = getClass.getResourceAsStream("/db.properties")
Alternatively you might try the built-in Lift Props meccano:
http://www.assembla.com/wiki/show/liftweb/Properties
If you use Mapper (= persistence framework that comes with Lift) you might have a look at:
http://www.assembla.com/spaces/liftweb/wiki/Mapper
If everything fails - ask the friendly lift community:
http://groups.google.com/group/liftweb
Hope that helps
Paul