-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more documentation, give example for api #2
Comments
Things I struggle with:
@Bean
public Default playDefaultController() {
// Need to provide this with Spring DI for Controllers.
return new Default();
}
public class ApplicationTest extends WithApplication {
@Override
protected Application provideApplication() {
final play.api.Application scalaApp = new SpringApplicationBuilder()
.build();
return new Application() {
@Override
public play.api.Application getWrappedApplication() {
return scalaApp;
}
@Override
public Configuration configuration() {
return new Configuration(scalaApp.configuration());
}
@Override
public Injector injector() {
return new DelegateInjector(scalaApp.injector());
}
};
}
} I can work around by providing an instance of controllers.Assets in my Spring configuration, leading me to the next problems:
|
Hi tkruse, Regarding the tests, I''m not too sure, I'm not actively maintaining that project. I don't have time to actively maintain, but contribution are more than welcome! :) |
Hi @remithieblin, There is a GuiceApplicationBuilder for Java, which has bindings() and disable() methods to modify bindings from application.conf. Overall I am not sure what is possible, most limitations come from Play2 itself I think, and their design decision to always load application.conf unless the JVM was started with special parameters. |
As another idea: It would be nice if SpringBuilder would read a config property spring.profiles.active to set ctx.getEnvironment().setActiveProfiles(...) Without that, projects will have to find other more hacky ways to set the Spring profile, such as always having to pass -Dspring.profiles.active=... to the JVM, as well as -Dconfig.resource=... for play |
@tkruse Thanks for the sample ApplicationTest, have tried using the same, beans are getting created but in services or in controller, Autowire binding is not working variables are null. Any thoughts on this. Thanks for sharing. [Update] Using SpringJUnit4ClassRunner, application object is created, how to inject application context present in Play Application to Test Context. |
@tkruse I have overridden spring testContext, now test cases are working with SpringJunit4Runner. |
@tkruse How you have resolved "controllers.Assets" error while running test case. |
Hi, |
Hm, for the time being I found no better solution than this: import controllers.Assets;
import play.api.http.HttpErrorHandler;
// ...
@Configuration
public class PlaySpringDIConfiguration
@Bean
// Required for tests only, Enable with Spring TEST profile only
@Profile("TEST")
public Assets playAssets(HttpErrorHandler handler) {
return new Assets(handler);
} |
However, that's where I got stuck, I could not nicely set spring.profiles.active within the test. Only passing this on the command line worked, I think... |
Spring provide "BootstrapWith" annotation and then created couple of super class. Regarding assets, I have to bind Assets in the application module. |
Any chance you can share the super classes and a test example? I can try reproducing the same using your description, but an example would be faster |
Hi,
nice project, but I struggled to get it to work with my play 2.5 spring 4.3 project.
Maybe you could add an example application config and Spring Configuration, like:
and
The text was updated successfully, but these errors were encountered: