1.在resources文件夹下面创建
application.conf
文件,文件的名字要完全一样
2.写一个helper类来获取字段
导入依赖
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.1</version>
</dependency>
代码中加载配置文件,设置延迟,获取application.conf文件中的类名
application.conf文件内容
nove.j = "what is my name"
help类中的内容
package config
import com.typesafe.config.{Config, ConfigFactory}
object ConfigHelp {
private lazy val load: Config = ConfigFactory.load()
val nn = load.getString("nove.j")
}
代码中获取
object App {
def main(args: Array[String]): Unit = {
val nn = ConfigHelp.nn
print(nn)
}
}