PropKit
PropKit tool class is used to operate external configuration files. PropKit can be used extremely conveniently at any time and space in the system. The following is a sample code:
public class AppConfigextends JFinalConfig{
public void configConstant(Constantsme) {
// Use for the first time The loaded configuration will become the main configuration, and the value can be obtained directly through PropKit.get(...) PropKit.use("a_little_config.txt");
me.setDevMode(PropKit.getBoolean("devMode"));
}
public void configPlugin(Pluginsme) {
// If the configuration is not loaded using use for the first time, you need to specify the configuration file name by using use each time and then get the value String redisHost= PropKit. use("redis_config.txt").get("host"); int redisPort= PropKit.use("redis_config.txt").getInt("port"); RedisPlugin rp =new RedisPlugin("myRedis", redisHost, redisPort );me.add(rp);
// If the configuration is not loaded using use for the first time, you can also get a Prop object first and then get the value through the object Prop p =PropKit.use(" db_config.txt");
DruidPlugin dp = new DruidPlugin(p.get("jdbcUrl"), p.get("user")…); me.add(dp);
}
}
public void configConstant(Constantsme) {
// Use for the first time The loaded configuration will become the main configuration, and the value can be obtained directly through PropKit.get(...) PropKit.use("a_little_config.txt");
me.setDevMode(PropKit.getBoolean("devMode"));
}
public void configPlugin(Pluginsme) {
// If the configuration is not loaded using use for the first time, you need to specify the configuration file name by using use each time and then get the value String redisHost= PropKit. use("redis_config.txt").get("host"); int redisPort= PropKit.use("redis_config.txt").getInt("port"); RedisPlugin rp =new RedisPlugin("myRedis", redisHost, redisPort );me.add(rp);
// If the configuration is not loaded using use for the first time, you can also get a Prop object first and then get the value through the object Prop p =PropKit.use(" db_config.txt");
DruidPlugin dp = new DruidPlugin(p.get("jdbcUrl"), p.get("user")…); me.add(dp);
}
}
As shown in the above code, PropKit can load multiple configuration files at the same time. The first loaded configuration file can be directly loaded using the PorpKit.get(...) method. Operation, the configuration file other than the first one to be loaded needs to use PropKit.use(…).get(…) to operate. The use of PropKit is not limited to YourJFinalConfig and can be used anywhere in the project. The underlying getProperty method of JFinalConfig relies on PropKit implementation.