SmartConfig

True type-safe configuration

Лицензия

Лицензия

Категории

Категории

config Библиотеки уровня приложения Configuration
Группа

Группа

com.github.sergeybudnik
Идентификатор

Идентификатор

smart.config
Последняя версия

Последняя версия

3.7.0
Дата

Дата

Тип

Тип

maven-plugin
Описание

Описание

SmartConfig
True type-safe configuration
Ссылка на сайт

Ссылка на сайт

https://github.com/SergeyBudnik/SmartConfig
Система контроля версий

Система контроля версий

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

Скачать smart.config

Как подключить последнюю версию

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

Зависимости

compile (7)

Идентификатор библиотеки Тип Версия
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)

Идентификатор библиотеки Тип Версия
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.4

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

Данный проект не имеет модулей.

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'

Версии библиотеки

Версия
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