首页  

play Configuration 配置读取     所属分类 play 浏览量 269
https://www.playframework.com/documentation/2.8.x/ScalaConfig

The Scala Configuration API

play.api.Configuration

obtain a Configuration object through Dependency Injection


conf/application.conf
conf/my.conf

conf/application.conf

# 包含 my.conf
include "my"
app=playdemo
my{
  name=tiger
}

conf/my.conf

my{
  key1=value1_new2
}

读取配置

package controllers
import play.api.Configuration
import play.api.mvc._
import javax.inject._

@Singleton
class ConfigController @Inject()(config: Configuration, cc: ControllerComponents) extends AbstractController(cc) {
  def configInfo() = Action { implicit request: Request[AnyContent] =>
    val app = config.get[String]("app")
    val name = config.get[String]("my.name")
    val value1 = config.get[String]("my.key1")
    Ok(s"app=$app,name=$name,value1=$value1")
  }
}


https://gitee.com/dyyx/hellocode/blob/master/demo/scala/play-rest-hello/app/controllers/ConfigController.scala

上一篇     下一篇
Scala中的 -> <- => {} ()

play框架调试关键代码

scala 包对象 package object

play action 要点

play HTTP routing

play框架日志