Configure with CDI

Configuration using CDI

Лицензия

Лицензия

Категории

Категории

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

Группа

org.honton.chas
Идентификатор

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

config-cdi
Последняя версия

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

0.1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

Configure with CDI
Configuration using CDI
Ссылка на сайт

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

https://github.com/chonton/config-cdi
Система контроля версий

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

https://github.com/chonton/config-cdi

Скачать config-cdi

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

<!-- https://jarcasting.com/artifacts/org.honton.chas/config-cdi/ -->
<dependency>
    <groupId>org.honton.chas</groupId>
    <artifactId>config-cdi</artifactId>
    <version>0.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.honton.chas/config-cdi/
implementation 'org.honton.chas:config-cdi:0.1.2'
// https://jarcasting.com/artifacts/org.honton.chas/config-cdi/
implementation ("org.honton.chas:config-cdi:0.1.2")
'org.honton.chas:config-cdi:jar:0.1.2'
<dependency org="org.honton.chas" name="config-cdi" rev="0.1.2">
  <artifact name="config-cdi" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.honton.chas', module='config-cdi', version='0.1.2')
)
libraryDependencies += "org.honton.chas" % "config-cdi" % "0.1.2"
[org.honton.chas/config-cdi "0.1.2"]

Зависимости

compile (8)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-databind jar 2.9.8
com.fasterxml.jackson.dataformat : jackson-dataformat-xml Необязательный jar 2.9.8
com.fasterxml.jackson.dataformat : jackson-dataformat-yaml Необязательный jar 2.9.8
com.fasterxml.jackson.module : jackson-module-mrbean Необязательный jar 2.9.8
com.jasonclawson : jackson-dataformat-hocon Необязательный jar 1.1.0
javax.enterprise : cdi-api jar 1.2
javax.inject : javax.inject jar 1
org.slf4j : slf4j-api jar 1.7.21

provided (1)

Идентификатор библиотеки Тип Версия
org.projectlombok : lombok jar 1.16.8

test (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12
org.jglue.cdi-unit : cdi-unit jar 3.1.3
org.mockito : mockito-core jar 1.10.19

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

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

Use CDI to inject application configuration.

ConfigurationCache is a generic class that reads configuration documents and fills pojos (Plain Old Java Objects) or reifies pojis (Plain Old Java Interfaces) with the parsed values. With this library CDI will inject ConfigurationCache sites marked with @Inject and @ConfigurationSource. The configuration source is read from the location specified in the @ConfigurationSource annotation.

public class MyClassThatNeedsConfiguration {

	@Inject @ConfigurationSource("classpath:conf-config-bean.conf")
	private ConfigurationCache<ConfigBean> configCache;
    
    public String doSomethingThatNeedsConfiguration() {
    	ConfigBean config = configCache.get();
        // use values from config
        // ...
	}
}

Features

  • Thread safe
  • Multiple configuration source document formats
  • Automatic reload of configuration values when document changes
  • Configuration set consistency
  • Annotation driven document source
  • Annotation driven document to object mapping
  • Configuration Interfaces as well as Objects

@ConfigurationSource elements

ConfigurationSource has two elements:

  • value - URI to locate the configuration source document. The file extension is used to determine the document data format.
  • interval - Number of milliseconds before refetching source document

Supported Data Formats

Configuration-cdi supports the following source file formats:

Single document to multiple configuration objects

It is possible to have a single document specified by multiple ConfigurationCache injection points. Each resultant object will be filled with its subset of attributes defined in the document.

Document per configuration object

It is also possible to have a document specified for each ConfigurationCache injection point.

Extra attributes

Attributes specified in the document without a corresponding configuration object attribute are ignored.

Missing attributes

Configuration object attributes without a corresponding attribute in the document are left as initialized by java.

Add to your maven project

<dependency>
  <groupId>org.honton.chas</groupId>
  <artifactId>config-cdi</artifactId>
  <version>0.1.2</version>
</dependency>

Add optional support for configuration interfaces

<dependency>
  <groupId>com.fasterxml.jackson.module</groupId>
  <artifactId>jackson-module-mrbean</artifactId>
  <version>2.7.4</version>
</dependency>

Add optional support for Yaml

<dependency>
  <groupId>com.fasterxml.jackson.dataformat</groupId>
  <artifactId>jackson-dataformat-yaml</artifactId>
  <version>2.9.8</version>
</dependency>

Add optional support for Conf

<dependency>
  <groupId>com.jasonclawson</groupId>
  <artifactId>jackson-dataformat-hocon</artifactId>
  <version>1.1.1</version>
</dependency>

Add optional support for Xml

<dependency>
  <groupId>com.fasterxml.jackson.dataformat</groupId>
  <artifactId>jackson-dataformat-xml</artifactId>
  <version>2.9.8</version>
</dependency>

Mapping Annotations

Jackson is used to parse documents and populate the configuration pojos. All of the standard Jackson annotations can be used to direct the document to object mapping.

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

Версия
0.1.2
0.1.0