Custom configuration files - Play! Framework 2.0

前端 未结 4 1307
离开以前
离开以前 2021-01-05 05:58

I have a question about loading properties from custom configuration files. I have tried two different approaches to loading my oauth.properties file but I can\

相关标签:
4条回答
  • 2021-01-05 06:07

    In a generic case, to fetch any File from the "/conf" directory, using Play 2.2 it can be done as follows (note that "/conf" is on the classpath, so you should not include it).

    Play.application().classloader().getResource("any_file");
    
    0 讨论(0)
  • 2021-01-05 06:18

    If you want to use scala.io.Source you can also do something like

    Source.fromFile(Play.getFile("path-in-your-play-project"))
    
    0 讨论(0)
  • 2021-01-05 06:19

    What worked for me with a file in /conf:

    import com.typesafe.config.ConfigFactory
    
    val myConfig = ConfigFactory.load("myfile.properties").getConfig("my.config.prefix")
    
    0 讨论(0)
  • 2021-01-05 06:21

    I'm not sure if conf is part of the classpath. So I would try /conf/oauth.properties or put the file into the classpath. Furthermore you should use Play.application.classloader() instead of Classloader.

    About the include: I still think you need to call Play.application().configuration().get("clientID");

    To analyze the situation you can start the app with -Dconfig.trace=loads and analyse the configuration with Play.application().configuration().root().render().

    Hope this give you enough hints so that you can solve your problem.

    0 讨论(0)
提交回复
热议问题