playframework-2.5

Play 2.5 disable csrf protection for some requests

℡╲_俬逩灬. 提交于 2019-12-01 07:17:15
问题 I'm writing my app using play framework v. 2.5.3 and use CSRF protection as it is described in official documentation. public class Filters implements HttpFilters { @Inject CSRFFilter csrfFilter; @Override public EssentialFilter[] filters() { return new EssentialFilter[]{csrfFilter.asJava()}; }} Of course, it works, as long as all of requests need to be filtered, but some of them should be bypassed. How can filters be configured to bypass requests to some specified route? Thanks for your help

Play.current is deprecated in play 2.5

一世执手 提交于 2019-11-30 19:12:16
I am currently using Play.current in the following way. import play.api.{Logger, Play} object ApplicationConfig { val app = Play.current def getConfInt(key: String): Option[Int] = { val result = app.configuration.getInt(key) result } } Since migrating to 2.5, I have a warning saying that it is deprecated with "This is a static reference to application, use DI instead" However, the doc doesn't exactly say how am I supposed to use DI instead. Thanks Depending on your use case you should now use Environment , ApplicationLifecycle and Configuration instead of Application In your case you are

Play.current is deprecated in play 2.5

早过忘川 提交于 2019-11-30 16:57:39
问题 I am currently using Play.current in the following way. import play.api.{Logger, Play} object ApplicationConfig { val app = Play.current def getConfInt(key: String): Option[Int] = { val result = app.configuration.getInt(key) result } } Since migrating to 2.5, I have a warning saying that it is deprecated with "This is a static reference to application, use DI instead" However, the doc doesn't exactly say how am I supposed to use DI instead. Thanks 回答1: Depending on your use case you should

Dependency injection with abstract class and object in Play Framework 2.5

巧了我就是萌 提交于 2019-11-30 11:48:29
问题 I'm trying to migrate from Play 2.4 to 2.5 avoiding deprecated stuff. I had an abstract class Microservice from which I created some objects. Some functions of the Microservice class used play.api.libs.ws.WS to make HTTP requests and also play.Play.application.configuration to read the configuration. Previously, all I needed was some imports like: import play.api.libs.ws._ import play.api.Play.current import play.api.libs.concurrent.Execution.Implicits.defaultContext But now you should use

Dependency injection with abstract class and object in Play Framework 2.5

橙三吉。 提交于 2019-11-30 00:21:07
I'm trying to migrate from Play 2.4 to 2.5 avoiding deprecated stuff. I had an abstract class Microservice from which I created some objects. Some functions of the Microservice class used play.api.libs.ws.WS to make HTTP requests and also play.Play.application.configuration to read the configuration. Previously, all I needed was some imports like: import play.api.libs.ws._ import play.api.Play.current import play.api.libs.concurrent.Execution.Implicits.defaultContext But now you should use dependency injection to use WS and also to use access the current Play application . I have something

Warning message running Play 2.5.x

为君一笑 提交于 2019-11-29 16:53:58
问题 Whenever I run my application with activator run I get the following warning: "The system cannot find the file BIN_DIRECTORY\..\conf\sbtconfig.txt" What does this message mean? Should I create this file? The application works fine. 回答1: @ps0604 Firstly, you should follow James Higgins-Thomas's 2nd answer and edit the C:\your\path\to\activator-dist-1.3.10\bin\activator.bat file and add a closing % symbol set SBT_HOME=%BIN_DIRECTORY% Secondly, the sbtconfig.txt found in the Scala directory C:

How do I perform an action on server startup in the Scala Play Framework?

北城余情 提交于 2019-11-27 02:09:18
问题 I have a config file servers.conf in my conf/ directory that is read by my ServerController whenever the route /servers is hit. This isn't performant because it requires a re-read of the configuration file on each successive hit when the file won't change. Further if there are problems with the config file, I can tell the user ASAP rather than throw an exception on a page hit. Currently I have this in my ServerController.scala : case class Server(ip: String, port: String) /** * This