Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graylog2/jadconfig
Annotation-driven configuration library for the Java programming language
https://github.com/graylog2/jadconfig
configuration google-guava google-guice guava guice java java-library joda
Last synced: 5 days ago
JSON representation
Annotation-driven configuration library for the Java programming language
- Host: GitHub
- URL: https://github.com/graylog2/jadconfig
- Owner: Graylog2
- License: apache-2.0
- Created: 2011-08-30T21:08:38.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2024-07-04T04:08:47.000Z (7 months ago)
- Last Synced: 2025-01-25T00:12:19.024Z (13 days ago)
- Topics: configuration, google-guava, google-guice, guava, guice, java, java-library, joda
- Language: Java
- Homepage:
- Size: 3.14 MB
- Stars: 23
- Watchers: 17
- Forks: 11
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JadConfig
[![Maven Central](https://img.shields.io/maven-central/v/org.graylog/jadconfig.svg)](http://mvnrepository.com/artifact/org.graylog/jadconfig)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 myList = new ArrayList();@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](http://www.joda.org/joda-time/). In order to use it just add the Joda-Time
dependency to your `pom.xml`:
joda-time
joda-time
2.9
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](https://github.com/google/guava/). In order to use
it just add the Google Guava dependency to your `pom.xml`:
com.google.guava
guava
18.0
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](https://github.com/google/guice/). In order
to use it just add the Google Guice dependency to your `pom.xml`:
com.google.inject
guice
4.0
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](https://github.com/google/guice/wiki/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`:
org.graylog
jadconfig
0.13.0
## Support
Please file bug reports and feature requests in [GitHub issues](https://github.com/Graylog2/JadConfig/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