I am working with Play! 2.4 and I am using Ebean as the ORM tool. All is good when i configure ebean through application.conf and use the default Ebeanserver created by play ebean.
What I would like to achieve though, is to be able to configure Ebeanserver dynamically and inject it. The application can be deployed in different production environments, in each environment the url, username, password may change. So I want to store the parameters that can vary in a separate configuration file and build the Ebeanserver object programatically.
I have tried followed this link: http://ebean-orm.github.io/docs/setup/guice , but I have not been successful. My configuration looks as follows:
EbeanServerProvider.java
public class EbeanServerProvider implements Provider<EbeanServer> {
@Override
public EbeanServer get() {
ServerConfig config = new ServerConfig();
config.setName("mysql");
config.loadFromProperties();
config.setDefaultServer(true);
return EbeanServerFactory.create(config);
}
}
binding the module using guice
bind(EbeanServer.class).toProvider(EbeanServerProvider.class).asEagerSingleton();
ebean.properties
datasource.default = mysql
datasource.mysql.databaseDriver=com.mysql.jdbc.Driver
datasource.mysql.databaseUrl="jdbc:mysql://localhost/playdb"
datasource.mysql.username=root
datasource.mysql.password=""
application.conf
ebean.default = ["models.*]
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/playdb"
db.default.username=root
db.default.password=""
I guess the problem is that I am not clear on what configuration is needed by play and what is needed by ebean. There is not a lot of good documentation on using ebean and play with Dependency injection. Any help is greatly appreciated.