Fork me on GitHub

Constretto - configuration made easy

The Constretto project is essentially about making it easier to configure your JVM-based applications. Constretto allows you to inject the runtime configuration into the running code, thus making it easy to reconfigure your application without having to redeploy. Constretto and all its subprojects is distributed under an ASF V2 license.


Add depedendency

Constretto is available from the central Sonatype OSS repository, so it is easy to add it to your project


If you're using Maven, add the following to your pom:



libraryDependencies += "org.constretto" % "constretto-core" % "2.2.3"

Add @Configuration or/and @Configure to POJO

In order to make your POJO "Constrettofied", you use the @Configuration (for fields and parameters) or @Configure (on methods, including constructors)

public class DataSourceConfiguration {

    private String myUrl;
    private String myPassword;
    private Integer version;

	// When no expression is explicitly given Constretto will use field name as key
    private String vendor;

    private String myUsername;

    public void configure(String url, @Configuration("password") String secret) {
        this.myUrl = url;
        this.myPassword = secret;

    public void setVersion(Integer version) {
        this.version = version;

    public String getUrl() {
        return myUrl;

    public String getUsername() {
        return myUsername;

    public String getPassword() {
        return myPassword;

    public String getVendor() {
        return vendor;

    public Integer getVersion() {
        return version;

Load configuration

Tell Constretto where to read configuration from by constructing a ConstrettoConfiguration object. Constretto-Core currently supports Java properties files, Encrypted Java properties files, Windows-style INI files, JSON, POJOs and System properties (automatically added when using the ConstrettoBuilder.

final ConstrettoConfiguration configuration = new ConstrettoBuilder(). // System properties are added as default
	.createPropertiesStore() // for standard Java property files 
		.done() // Multiple resources may be added
	.createEncryptedPropertiesStore(SHARED_SECRET) // for Java property files with encrypted values
	.createIniFileConfigurationStore() // For Windows-style INI files
	.createJsonConfigurationStore() // Configuration in JSON format 
	.createObjectConfigurationStore() // Configuration as POJOs

Inject configuration

Use your ConstrettoConfiguration object to inject configuration in your POJOs.

DataSourceConfiguration dataSourceConfiguration = new DataSourceConfiguration();
configuration.on(dataSourceConfiguration); // for existing objects
DataSourceConfiguration dbConfig = // Constretto constructs the pojo and injects configuration

Environment tagging support

Constretto supports storing environment-specific configuration by using tags. When using the Java property file format you can specify it using the @(tag) prefix:

	somedb.username=default username
	@production.somedb.username=username in production
	@systest.somedb.username=username in system test

Telling Constretto which tags to look up

Constretto uses a System property, or System environment property to know what tags to look up. this property is called "CONSTRETTO_TAGS"

	$java MyApp -DCONSTRETTO_TAGS=tag1,tag2,tag3
	$export CONSTRETTO_TAGS=tag1,tag2,tag3
	$java Myapp