我想在运行时为我的Play项目设置数据库连接。我知道我可以设置属性运行时用下面的代码:更改application.conf运行时?
@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);
}
}
但是,当执行文件上面的代码实际上没有变化,我认为只是在内存中。
如何设置数据库属性并强制播放!要使用此属性来连接到正确的数据库onApplicationStart?
谢谢!
UPDATE 2012-01-29
溶液通过插件是可能的。在这个插件中,我必须重写onConfigurationRead(),并在此时将属性应用于配置文件。我会尽快发布一些代码,只要我有这个时间。
这对我不起作用,因为我会将此应用程序交付给客户。他们都有自己的连接设置。该设置也可能随时间而改变。我想避免我的客户必须解压.war文件(部署在tomcat上)并更改conf文件。我会尝试创建像绿色建议的单独插件。谢谢。 – adis 2012-01-29 19:33:35