简体   繁体   中英

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.

You can use Typesafe Config which is what Play uses internally.

With an application.conf file in your src/main/resources looking like:

db {
  table {
    name = employees
  }
}

You can then load it up on your Scala code like this:

import com.typesafe.config.ConfigFactory

val conf = ConfigFactory.load();
val dbTableName = conf.getString("db.table.name")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM