Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change application.conf runtime?

I want to set the database connection at run time for my Play project. I know that I can set a property run time with the following code:

@OnApplicationStart public class Bootstrap extends Job
{
   @Override public void doJob()
   {
     // now set the values in the properties file
     Play.configuration.setProperty("db.driver", dbDriver);
     Play.configuration.setProperty("db.url", dbUrl);
     Play.configuration.setProperty("db.user", dbUsername);
     Play.configuration.setProperty("db.pass", dbPassword);
   }
}

But when executing the code above the file is not actually changed, I think just in memory.

How can I set the database properties and force Play! to use this properties in order to connect to the right database onApplicationStart?

Thanks!

UPDATE 2012-01-29

Solution is possible via a plugin. In this plugin I have to override onConfigurationRead() and apply the properties to the configuration file at that moment. I will try to post some code as soon as I have time for this.

like image 799
adis Avatar asked Nov 04 '22 06:11

adis


1 Answers

By the time you change the properties, the DB plugin is already initialized. You need to write a plugin and overwrite the onConfigurationRead() method, then put your new settings there. Paly's dbplugin will init later on.

like image 127
Gelin Luo Avatar answered Nov 13 '22 03:11

Gelin Luo