JadConfig

Annotation-driven configuration library for the Java programming language

License

License

Categories

Categories

config Application Layer Libs Configuration
GroupId

GroupId

com.github.joschi
ArtifactId

ArtifactId

jadconfig
Last Version

Last Version

0.13.0
Release Date

Release Date

Type

Type

jar
Description

Description

JadConfig
Annotation-driven configuration library for the Java programming language
Project URL

Project URL

https://github.com/joschi/JadConfig
Source Code Management

Source Code Management

https://github.com/joschi/JadConfig

Download jadconfig

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.21
joda-time : joda-time Optional jar 2.9.4
com.google.inject : guice Optional jar 4.0
com.google.guava : guava Optional jar 19.0

test (3)

Group / Artifact Type Version
org.slf4j : slf4j-simple jar 1.7.21
junit : junit jar 4.12
com.google.code.findbugs : jsr305 jar 3.0.1

Project Modules

There are no modules declared in this project.

JadConfig

Build Status Coverage Status Maven Central

JadConfig is a minimalistic annotation-driven configuration parsing framework for Java with minimal dependencies.

Example

Here is a quick example of a Java class used as configuration bean:

public class ConfigurationBean {
  @Parameter("my.stringList")
  public List<String> myList = new ArrayList<String>();

  @Parameter("my.integer")
  public int myInteger = 1;

  @Parameter(value = "my.uri", required = true)
  public URI myURI;
}

and how you initialize it with JadConfig:

ConfigurationBean bean = new ConfigurationBean();
new JadConfig(new PropertiesRepository("my.properties"), bean).process();

Assert.assertNotNull(bean.myList);

You can also use multiple repositories as source for your configuration (first match wins):

ConfigurationBean bean = new ConfigurationBean();
new JadConfig(
        Arrays.asList(
            new EnvironmentRepository(),
            new PropertiesRepository("my.properties")
        ),
        bean)
    .process();

Assert.assertNotNull(bean.myList);

Joda-Time

JadConfig optionally supports Joda-Time. In order to use it just add the Joda-Time dependency to your pom.xml:

<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.9</version>
</dependency>

And register JodaTimeConverterFactory with the JadConfig instance:

JadConfig jadConfig = new JadConfig(repository, configurationBean);
jadConfig.addConverterFactory(new JodaTimeConverterFactory());
jadConfig.process();

Guava

JadConfig optionally supports some data types from Google Guava. In order to use it just add the Google Guava dependency to your pom.xml:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>18.0</version>
</dependency>

And register GuavaConverterFactory with the JadConfig instance:

JadConfig jadConfig = new JadConfig(repository, configurationBean);
jadConfig.addConverterFactory(new GuavaConverterFactory());
jadConfig.process();

Currently the following data types are being supported:

  • CacheBuilderSpec
  • HashCode
  • HostAndPort
  • HostSpecifier
  • InternetDomainName
  • MediaType
  • UnsignedInteger
  • UnsignedLong

Guice

JadConfig optionally supports registering named bindings in Google Guice. In order to use it just add the Google Guice dependency to your pom.xml:

<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>4.0</version>
</dependency>

And register NamedConfigParametersModule with the Guice Injector:

Injector injector = Guice.createInjector(new NamedConfigParametersModule(Collections.singleton(configurationBean)));

The name of the bindings are identical to the @Parameter name.

Example:

public class MyConfigBean {
    @Parameter("my.custom.config")
    public String customConfig;
}

// Create injector and register NamedConfigParametersModule.
// [...]

public class MyClass {
    @Inject
    public MyClass(@Named("my.custom.config") String customConfig) {
        // ...
    }
}

// MyClass will be instantiated with the value of customConfig from the MyConfigBean instance.
MyClass myClass = injector.getInstance(MyClass.class);

Please note that nullable properties which should be injected by Guice have to be annotated with @Nullable, see UseNullable in the Guice wiki for details.

Maven

To use JadConfig in your project using Maven add the following lines into the dependencies section of your pom.xml:

<dependency>
    <groupId>com.github.joschi</groupId>
    <artifactId>jadconfig</artifactId>
    <version>0.13.0</version>
</dependency>

Support

Please file bug reports and feature requests in GitHub issues.

License

JadConfig is being released under the Apache License, Version 2.0. You can download the complete license text at http://www.apache.org/licenses/LICENSE-2.0.html

Versions

Version
0.13.0
0.12.2
0.12.1
0.12.0
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4
0.3
0.2
0.1