Play.current is deprecated in play 2.5

后端 未结 1 1010

I am currently using Play.current in the following way.

import play.api.{Logger, Play}

object ApplicationConfig {

  val app = Play.current
  def getConfInt         


        
相关标签:
1条回答
  • 2021-01-05 05:19

    Depending on your use case you should now use Environment, ApplicationLifecycle and Configuration instead of Application

    In your case you are actually interested in the configuration so the way to do this in Play 2.5.x would be like this:

    class HomeController @Inject() (configuration: play.api.Configuration) extends Controller {
    
      def config = Action {
        Ok(configuration.underlying.getInt("some.config.key"))
      }
    
    }
    

    The example I provided is for a controller but you can use this approach also on other places in your application. I just didn't like the ApplicationConfig object you provided - consider refactoring it when migrating to Play 2.5.x - DI is now the way to go

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