scala - Scala Akka 项目中 .properties 文件的位置
问题描述
我有一个 akka 项目,其中我正在Properties
使用代码构建一个对象:
import java.io.FileNotFoundException
import java.util.Properties
import scala.io.Source
val configPath = "hikari.properties"
val url = getClass.getResource(hikariConfigPath)
val properties: Properties = new Properties()
if (url != null) {
val source = Source.fromURL(url)
properties.load(source.bufferedReader())
} else {
println("properties file cannot be loaded at path " + configPath)
throw new FileNotFoundException("Properties file cannot be loaded”)
}
这给了我“无法在路径 hikari.properties 加载属性文件”</p>
有这个特例:
java.io.FileNotFoundException: Properties file cannot be loaded
at model.daos.JavaConnectionFactoryBuilder$.buildDataSource(JavaConnectionFactory.scala:25)
我已按照https://zetcode.com/articles/hikaricp/的建议将hikari.properties
文件放在目录中src/main/resources
我该如何解决这个问题?
解决方案
您正在加载一个不存在的文件hikari.
而不是hikari.properties
.
它应该是:
val hikariConfigPath = "hikari.propertiez"
推荐阅读
- azure-devops - 来自守护程序的错误响应:未经授权:需要身份验证
- python - 本地搜索 Jupyter 笔记本
- javascript - javascript (window).unload 不适用于某些 chrome 版本
- java - 如何在使用 Selenium Java 时传递条件变量?
- reactjs - 有没有办法为所有属性设置为 true 的元素添加一个类?
- python - 我在python中使用了随机库,对我来说这是第一次,你能帮帮我吗?
- matplotlib - ModuleNotFoundError:使用 plotly 时没有名为“plotly.validators.bar._xaxis”的模块
- node.js - 使用单个池将创建多少个会话?
- reactjs - 我只希望管理员路由和用户限制
- android - 没有水平滚动的日历视图