scala读取配置文件内容
方法1:默认加载方式,读取./src/main/resources下文件
ConfigFactory.load(f),例子(亲测可用):
pom.xml中引入
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.2.1</version>
</dependency>
resources/application.conf 文件内容
web{
hdfsLog="hdfs://192.168.1.101:9000"
}
scala代码
import com.typesafe.config.ConfigFactory
object application {
//获取配置文件位置;我的在resources下面
val config = ConfigFactory.load("application.conf")
//application.conf中 web.hdfsLog 的内容
val logUrl:String = config.getString("web.hdfsLog")
println(logUrl)
}
方法二:读取路径下的配置文件
object test02{
def main(args: Array[String]): Unit ={
val prop = new Properties()
val inputStream = test02.getClass.getClassLoader.getResourceAsStream("application.properties")
prop.load(inputStream);
val url= prop.get("test.url")
println(url)
}
}
标签:读取,val,scala,application,config,配置文件
From: https://www.cnblogs.com/atao-BigData/p/16739939.html