In other languages like Python it is possible to perform programming logic in the configuration files and in Java this is not allowed because it is a compiled language.
I decided to encapsulate the settings of the .properties
file in a Java object, so I have the advantage of being able to validate the file information, generate programming logic and even use Eclipse autocomplete, but I have the disadvantage of not being able to create properties dynamically, so I have the doubt whether this is a good practice or just something to complicate further development.
Ex:
Config.properties file
email.user=user
email.host=smtp.email.com
email.auth=true
Class:
public class Config {
private String emailUser;
private String emailHost;
private Boolean emailAuth;
public Config() {
Properties properties = new Properties();
try {
properties.load(Config.class.getResourceAsStream("/config.properties"));
emailUser = properties.getProperty("email.user");
emailHost = properties.getProperty("email.host");
emailAuth = Boolean.valueOf(properties.getProperty("email.auth"));
} catch (IOException e) {
e.printStackTrace();
}
}
//Somente Gets
}