How do i use play ws library in normal sbt project instead of play?

前端 未结 2 1328
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-02 16:32

When i tried using Play WS library in a normal sbt project instead of play project I was bound to use play.api.Play.current and got java.lang.RuntimeException:

2条回答
  •  囚心锁ツ
    2021-02-02 17:03

    Usage in 2.4.x

    import play.api.libs.ws.ning.NingWSClient   
    
    val wsClient = NingWSClient()
    wsClient.url("http://wwww.something.com").get()
    

    build.sbt :

    libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.4.3"
    

    Usage in 2.5.x

    import play.api.libs.ws.ahc.AhcWSClient
    
    implicit val actorSystem = ActorSystem()
    implicit val materializer = ActorMaterializer()
    wsClient.url("http://wwww.something.com").get()
    
    //at the very end, to shutdown stuff cleanly :
    wsClient.close()
    actorSystem.terminate()
    

    build.sbt :

    libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.5.4"
    

    Logs

    As someone noted in the comment, by default you might get a bunch of verbose logs coming from the underlying async-http-client. One way to fix it is to start configuring a logback.xml, and placing it in src/main/resources

    
    
    
    
    
        
            
            %d %coloredLevel %t - %logger - %message%n%xException
        
    
    
    
    
    
    
    
        
    
    
    
    

提交回复
热议问题