Accessing the application.conf properties from java class with Play! 2.0

前端 未结 13 2175
一整个雨季
一整个雨季 2020-12-24 10:37

I want to add an object to the Global scope, and in order to construct it I need to pass it a path to a file. I don\'t want to hard code the file path in the source, and so

13条回答
  •  悲哀的现实
    2020-12-24 10:54

    Even if it seems simple, here is the scala way to get properties from configuration file :

    Play 2.0 and 2.1 :

    import play.api.Play.current
    ...
    Play.application.configuration.getString("your.key")
    

    Play 2.2 and +

    import play.api.Play.current
    ...
    current.configuration.getString("your.key")
    

    Using Typesafe config

    import com.typesafe.config.ConfigFactory
    ...
    ConfigFactory.load().getString("your.key");
    

提交回复
热议问题