Hi guys! I would like to share some interesting ideas about the
configuration properties functionality. I have my own impl of config
properties (there was no deltaspike when I have implemented it). Having the
following code:

public interface MainConfigurationProperties extends Configuration {

    @ConfigurationProperty(defaultValue="en")
    String SYSTEM_LANGUAGE = "system.language";

    String SYSTEM_USER_DISPLAY_NAME = "system.displayname";
}

@Inject
@Config(name = MainConfigurationProperties.SYSTEM_USER_DISPLAY_NAME)
private String configSystemUserDisplayName;

//an exception will be thrown for this because there is no constant for
this defined in the Configuration interfaces
@Inject
@Config(name = "something_random")
private String random;

Each configuration property should be declared as a constant in an
interface extending the Configuration interface (this could even be
implemented with enums). At startup I read all constants and validate the
injection of configuration properties if they match such constant and also
make sure there is no constant that's left unused. With this I make sure
that the properties are type (refactor) safe. Another benefit of declaring
constants for the properties is that i can list them in a web page so the
devs can see a list with all available properties and seach in that list.
There is also a default value declared with annotation on the constant for
the particular property if the property is missing in the config file, the
default value declared in the annotation is used.

Reply via email to