Cmd configure with CDI

Configuration using CDI

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

org.honton.chas
ArtifactId

ArtifactId

cmd-config-cdi
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Cmd configure with CDI
Configuration using CDI
Project URL

Project URL

https://github.com/chonton/config-cdi
Source Code Management

Source Code Management

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

Download cmd-config-cdi

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
com.beust : jcommander jar 1.48
javax.annotation : javax.annotation-api jar 1.2
javax.enterprise : cdi-api jar 1.2
javax.interceptor : javax.interceptor-api jar 1.2

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.8

test (4)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.1.7
junit : junit jar 4.12
org.jboss.weld.se : weld-se-core jar 2.3.4.Final
org.mockito : mockito-core jar 1.10.19

Project Modules

There are no modules declared in this project.

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.

Versions

Version
0.1.0