-
Notifications
You must be signed in to change notification settings - Fork 1
Other Solution 2
Wuyi Chen edited this page Aug 6, 2018
·
5 revisions
@PropertySourceX({ "config/app.properties" })
public class AppConfig3 extends ConfigurationY {
@ValueX("app.host")
static String host;
@ValueX("app.api_key")
static String apiKey;
@ValueX("app.username")
static String username;
@ValueX("app.password")
static String password;
}
This solution uses a static class. It loads the parameters from the config file by inheriting the ConfigurationY class. The ConfigurationY class has the ability to detect all the sub-classes and help them load parameters. This is the most automatic solution with the minimal amount of code. It also uses the @PropertySourceX annotation for storing the path and uses the @ValueX annotation for the name of parameters.
- If an exception occurs when loading the parameter, it can not be captured (Because this process is in the ConfigurationY class).
- This class can only map to one external configuration.
- The ConfigurationY class need to scan all the sub-classes. So the performance will be degraded by this reason.