SmartConfig

True type-safe configuration

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

com.github.sergeybudnik
ArtifactId

ArtifactId

smart.config
Last Version

Last Version

3.7.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

SmartConfig
True type-safe configuration
Project URL

Project URL

https://github.com/SergeyBudnik/SmartConfig
Source Code Management

Source Code Management

http://github.com/SergeyBudnik/SmartConfig/tree/master

Download smart.config

How to add to project

<plugin>
    <groupId>com.github.sergeybudnik</groupId>
    <artifactId>smart.config</artifactId>
    <version>3.7.0</version>
</plugin>

Dependencies

compile (7)

Group / Artifact Type Version
com.github.sergeybudnik : smart.config.data jar 3.2.0
org.apache.maven : maven-plugin-api jar 3.0
org.apache.maven : maven-project jar 2.2.1
net.sourceforge.jenesis4java : jenesis4java jar 2.19
jalopy : jalopy jar 1.5rc3
com.typesafe : config jar 1.3.2
org.projectlombok : lombok jar 1.16.20

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.4

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

SmartConfig

Maven Central

Maven Central

About

TBD

Main features

  1. True typesafe configuration
  2. Strong properties validation
  3. Possibility to subscribe to properties change

Integration

Lets imagine that you are developing a java-based server, which reads currencies from the database and distributes them to your website through Rest service.

You should be able to configure server to work in three environments: SIT, UAT, Prod Also your production servers are located in different countries: Russia, USA and India

You want to configure:

  1. Database URL
  2. Language that you want to use for your Rest services response

So, lets get started!

First, create a space configuration file (located: ${project.basedir}/src/main/resources/config-spaces.conf)

space {
    env: [sit, uat, prod]
    location: [no_location, rus, usa, india]
}

points [
    {env: sit, location: no_location},
    {env: uat, location: no_location},
    {env: prod, location: rus},
    {env: prod, location: usa},
    {env: prod, location: india},
]

Now, create a configuration file with the values (located: ${project.basedir}/src/main/resources/config.conf)

database.url {
    ~sit: 'my_sit_database'
    ~uat: 'my_uat_database'
    ~prod: 'my_prod_database'
}

language {
    ~default: 'eng' // ~default - special keyword for default values
    ~rus: 'russia'
}

Add the following lines to your project pom.xml

<properties>
    <smart.config.csvProperties>${project.basedir}/src/main/resources/config.conf</smart.config.csvProperties>
    <smart.config.dimensions>${project.basedir}/src/main/resources/config-spaces.conf</smart.config.dimensions>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.sergeybudnik</groupId>
        <artifactId>smart.config.data</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.github.sergeybudnik</groupId>
            <artifactId>smart.config</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>jenesis4java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <relativeDirectory>/smart-generated-sources/smart-config</relativeDirectory> <!-- Optional -->
                <csvProperties>${project.basedir}/src/main/resources/smart-config-test.conf</csvProperties> <!-- Required -->
                <dimensions>${project.basedir}/src/main/resources/smart-config-dimensions.conf</dimensions> <!-- Required -->
            </configuration>
        </plugin>
    </plugins>
</build>

Finish!

Run 'mvn clean install'

After plugin execution, you will be able to work with properties in a following way:

SmartConfig smartConfig = SmartConfigProperties.getConfig("prod", "usa");

String databaseUrl = smartConfig.getDatabaseUrl();
SmartConfigValue<String> databaseUrlConfig = smartConfig.getDatabaseUrlConfig();

System.out.println(databaseUrl); // Prints 'my_prod_database'

Versions

Version
3.7.0
3.6.1
3.6.0
3.5.0
3.4.1
3.4.0
3.2.1
3.2.0
3.1.0
3.0.0
2.0.1
2.0.0
1.0.6
1.0.4
1.0.3
1.0.2
1.0.1