1.在pom文件中引入依赖
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.3</version>
</dependency>
2.在resources中创建application.conf文件
db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://hadoop002:3306"
db.default.user="root"
db.default.password="root"
db.default.database=test
3.在代码中使用ConfigFactory获取变量值
object ParamsApp {
def main(args: Array[String]): Unit = {
val config = ConfigFactory.load()
val url = config.getString("db.default.url")
val user = config.getString("db.default.user")
val password = config.getString("db.default.password")
println(url + "-" + user + "-" + password)
}
}