playframework-2.4

Play 2.4: How do I disable routes file loading during unit tests?

最后都变了- 提交于 2019-12-03 03:19:27
Background : I am using Play 2.4 (Java) with InjectedRoutesGenerator and a Guice module to configure various dependencies. But during unit tests, the FakeApplication is trying to load all the Controllers from routes file through the injector and some of them are failing due to external dependencies not available in the unit test environment. How do I disable the default routes file processing during unit tests that extend from play.test.WithApplication? Or how can I replace the default routes with a custom routes file? I tried to use the play.http.router config option override referenced here

Configuration depending on launch mode

拈花ヽ惹草 提交于 2019-12-02 23:35:24
Play can be launched in dev mode (via run ), in production mode (via start ) or in test mode. Is there a way to provide a different config file ( conf/application.conf ) depending on which mode it is launched in? I usually have a base configuration ( application.conf ) and three extra configs per environment. In Play Framework 2.4 it can be done by extending GuiceApplicationLoader and merging base conf with your environment specific conf. You can go one step forward and provide different guice modules per environment. Scala version: class CustomApplicationLoader extends GuiceApplicationLoader

Play Framework @routes.Assets.at Compilation Error

痴心易碎 提交于 2019-12-02 17:55:19
I'm using Play 2.4.0 and I've been trying to follow the tutorial from the main page: https://playframework.com/ which is for Play 2.3 and after solving a couple of issues regarding changes in the Ebean ORM from version 2.3 to 2.4, I'm stuck with the following error: Compilation error value at is not a member of controllers.ReverseAssets My index.scala.html : @(message: String) @main("Welcome to Play") { <script type='text/javascript' src="@routes.Assets.at("javascripts/index.js")"></script> <form action="@routes.Application.addPerson()" method="post"> <input type="text" name="name" /> <button

GuiceApplicationLoader configuration error

删除回忆录丶 提交于 2019-12-02 09:27:12
So, I'm trying to implement compile time DI with something that looks like this: package modules class MyModule extends AbstractModule { def configure() { bind(classOf[MyT]).to(classOf[MyTImpl]) } } class MyApplicationLoader extends GuiceApplicationLoader { override protected def builder(context: ApplicationLoader.Context): GuiceApplicationBuilder = { initialBuilder .in(context.environment) .loadConfig(context.initialConfiguration) .overrides(overrides(context): _*) .load(new MyModule) } } application.conf includes a line: play.application.loader = "modules.MyApplicationLoader" However, when I

Migrating to anorm2.4 (with play 2.4): ToStatement[T] and ToStatement[Option[T]]

孤人 提交于 2019-12-02 05:01:48
问题 Up until the anorm included with play 2.3, I could write the following: implicit val arbitraryClassToStatement = new ToStatement[ArbitraryClass] { def set( s: java.sql.PreparedStatement, index: Int, aValue: ArbitraryClass ) : Unit = { s.setString( index, ArbitraryClass.definingString ) } } and this would help insert the SQL("INSERT INTO SomeTable Values( {nonNullAc}, {possiblyNullAc} )" ).on( 'nonNullAc -> ArbitraryClass( "abcd" ), 'possiblyNullAc -> Option( ArbitraryClass( "abcd" ) ) )

Can't connect to mysql database with play-slick 1.0.1/slick 3.0 : configuration error

别来无恙 提交于 2019-12-02 04:41:43
I'm trying to migrate from anorm to slick, using play 2.4.2, and getting a configuration error: play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [dethcs]] at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.0.jar:2.4.0] ... Caused by: slick.SlickException: Error getting instance of Slick driver "slick.driver.MySQLDriver" ... Caused by: java.lang.NoSuchMethodException: slick.driver.MySQLDriver.<init>() Previous answers I've found on SO have focused on having the right MySQL driver and other dependencies. I believe my build.sbt covers the

Migrating to anorm2.4 (with play 2.4): ToStatement[T] and ToStatement[Option[T]]

こ雲淡風輕ζ 提交于 2019-12-02 02:28:13
Up until the anorm included with play 2.3, I could write the following: implicit val arbitraryClassToStatement = new ToStatement[ArbitraryClass] { def set( s: java.sql.PreparedStatement, index: Int, aValue: ArbitraryClass ) : Unit = { s.setString( index, ArbitraryClass.definingString ) } } and this would help insert the SQL("INSERT INTO SomeTable Values( {nonNullAc}, {possiblyNullAc} )" ).on( 'nonNullAc -> ArbitraryClass( "abcd" ), 'possiblyNullAc -> Option( ArbitraryClass( "abcd" ) ) ) meaning that both ArbitraryClass and Option[ ArbitraryClass ] would be satisfied by it. This seems to no

How to inject something into a form

故事扮演 提交于 2019-12-01 09:42:32
Since play 2.4.0, we can use a DI framework. I am trying to use DI in my app. I moved my jpa finders from static methods on my models classes to methods in a service layer that I inject into my controllers. My main problem is that I have some forms with a validate method and in my validate methode I use some finders. For exemple in a login form I use a "User.authenticate" method. Now that I have replaced this static method to a new one on my UserSvc, I want to inject my service into my Form but it does not work. It seems that it is not possible to inject something into a Form so how can I

How to enable trace/debugging output with Anorm on Play 2.4.0

半腔热情 提交于 2019-12-01 08:22:14
With Play 2.4.0 Anorm got moved to an external package and logging got changed to LogBack ( http://logback.qos.ch ) All well and good but nowhere are the class/package names obvious for tracing SQL calls. The "obvious" (based on the import statements) <logger name="anorm" level="TRACE" /> did nothing and I also tried <logger name="anorm.SQL" level="TRACE" /> just in case it needed to be more specific. Google searches just dead needed so I'm at a loss. Anyone? You can intercept calls going thru JDBC driver using log4jdbc I have used successfully with JPA/hibernate and Hikary on Play 2.4, the

Caching an action in a multi-language website using Play Framework's Cached API

天大地大妈咪最大 提交于 2019-11-30 11:03:00
In order to cache actions per label and language for a given number of seconds, I wrote the following helper method (where label, is the name I give to my action): def cacheResponseFor(label: String, duration: Int)(action: EssentialAction) = { Cached({r: RequestHeader => (label + getLanguage(r))}, duration){ action } } def getLanguage(request: RequestHeader): String = { request.cookies .get(helpers.SessionHelpers.LANGUAGE_SESSION) .map(_.value) .getOrElse(helpers.LanguageHelpers.FRENCH) } But I'm experiencing something weird, when I try to cache an Action for 60s and switch languages in the