Play framework is joining the Typesafe Stack — More information in the official announcement
Manual, tutorials & references
Get help with google
The spring support module help you to integrate Spring managed beans with a play application.
In the /conf/application.conf file, enable the Spring module by adding this line:
# The spring module
module.spring=${play.path}/modules/spring
In the conf/ directory of the application you can then create a application-context.xml file and define some beans.
For example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springsource.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="test" class="utils.Test" />
</beans>
You can obtain bean instances from the application code, using the play.modules.spring.Spring helper.
public Application extends Controller {
public static void index() {
Test test = Spring.getBeanOfType(Test.class);
...
}
}
You can now use the @Inject annotation to automatically inject defined beans in your controllers, jobs and mailer.
It works on static fields defined in these artefact. For example to inject a PriceWatcher service defined in Spring to one of your controller, just do:
public class Application extends Controller {
@Inject
static PriceWatcher prices;
public static void index() {
prices.getAll(); // prices is defined here
}
}
Auto-reload should work as exepected.
Comments
Use this form to add corrections, additions and suggestions about the documentation on this page. Please ask questions on the play-framework group instead. Support requests, bug reports, and off-topic comments will be deleted without warning.