[英]How to secure simple configuration in plain scala project?
I have a few properties that I want to protect from just lying in my class, just string properties for now, for example: 我有一些我想保护的属性,而不仅仅是在我的类中,现在只是字符串属性,例如:
class MyClass {
protected val dbTableName: String = "employees"
}
is there a more secure way to put this configuration in somewhere? 有没有更安全的方法将此配置放置在某处?
in play framework i used Configuration file and then I could use .getString
or whatever, but in this case I dont have play and I want to make it cleaner and more secure. 在播放框架中,我使用了配置文件,然后可以使用
.getString
或其他任何方式,但是在这种情况下,我没有播放功能,因此我想使其更加整洁和安全。
You can use Typesafe Config which is what Play uses internally. 您可以使用Play内部使用的Typesafe Config 。
With an application.conf
file in your src/main/resources
looking like: 在
src/main/resources
有一个application.conf
文件,如下所示:
db {
table {
name = employees
}
}
You can then load it up on your Scala code like this: 然后,您可以像下面这样将其加载到Scala代码上:
import com.typesafe.config.ConfigFactory
val conf = ConfigFactory.load();
val dbTableName = conf.getString("db.table.name")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.