common-configuration

Provides Spring config and ServerConfig necessary to support configuration

License

License

Categories

Categories

Configuration Application Layer Libs config
GroupId

GroupId

nz.ac.auckland.common
ArtifactId

ArtifactId

common-configuration
Last Version

Last Version

3.5
Release Date

Release Date

Type

Type

jar
Description

Description

common-configuration
Provides Spring config and ServerConfig necessary to support configuration
Project URL

Project URL

https://github.com/uoa-group-applications/common-configuration
Source Code Management

Source Code Management

https://github.com/uoa-group-applications/common-configuration

Download common-configuration

How to add to project

<!-- https://jarcasting.com/artifacts/nz.ac.auckland.common/common-configuration/ -->
<dependency>
    <groupId>nz.ac.auckland.common</groupId>
    <artifactId>common-configuration</artifactId>
    <version>3.5</version>
</dependency>
// https://jarcasting.com/artifacts/nz.ac.auckland.common/common-configuration/
implementation 'nz.ac.auckland.common:common-configuration:3.5'
// https://jarcasting.com/artifacts/nz.ac.auckland.common/common-configuration/
implementation ("nz.ac.auckland.common:common-configuration:3.5")
'nz.ac.auckland.common:common-configuration:jar:3.5'
<dependency org="nz.ac.auckland.common" name="common-configuration" rev="3.5">
  <artifact name="common-configuration" type="jar" />
</dependency>
@Grapes(
@Grab(group='nz.ac.auckland.common', module='common-configuration', version='3.5')
)
libraryDependencies += "nz.ac.auckland.common" % "common-configuration" % "3.5"
[nz.ac.auckland.common/common-configuration "3.5"]

Dependencies

compile (5)

Group / Artifact Type Version
nz.ac.auckland.composite : composite-configuration jar [3.2,)
net.stickycode.configuration : sticky-configuration jar [1.5, 2)
nz.ac.auckland.composite : composite-spring jar [4,)
nz.ac.auckland.composite : composite-logging-api jar [2,)
commons-io : commons-io jar 2.4

provided (2)

Group / Artifact Type Version
nz.ac.auckland.composite : composite-servlet jar [1.3,)
nz.ac.auckland.composite : composite-spring-web jar [4,)

test (2)

Group / Artifact Type Version
nz.ac.auckland.composite : composite-unittest jar [2.4,3)
nz.ac.auckland.composite : composite-logging-deploy jar [3.4,)

Project Modules

There are no modules declared in this project.

commons-configuration

This provides a Spring scanned configuration file to support the @ConfigKey annotation from Sticky Code that injects System properties into your Spring objects.

e.g.

@UniversityComponent
class MyClass {
  @ConfigKey("person.name") String name
  @ConfigKey("person.age") Integer age
  @ConfigKey Boolean alive   // myclass.alive
  @ConfigKey List<String> aliases // myclass.aliases
  @ConfigKey Map<String, Integer> childrenAges  // myclass.childrenAges
}

in system properties you would have

person.name=fred
person.age=35
myClass.alive=true
myClass.aliases=The Hammer, Sooty, Sweep
myClass.childrenAges=Barbara:7, William:2

You can include in your class a @PostConfigured annotation to then do post processing on the configuration.

@UniversityComponent
class AlsoMyClass {
   @ConfigKey String parts = "gibberish"
   @ConfigKey String password


   @PostConfigured
   public void configure() {
     // do something here
   }
}

Configuration Sources

There are two - the Jar Manifest file is first, the System Properties are second. Jar Manifest's can't use keys with a "." in their name, so those are immediately skipped.

Alternatives

We can use the @Value annotation from Spring, but this has a number of "issues":

  • @Value annotated fields in base classes will not pull their configuration settings when the bean is configured
  • @Value requires you to specify where your properties are coming from, which generally is undesirable as the source of configuration is extensible.
  • @Value's default mechanism is clumsy, requiring error prone stringization of defaults

Web Usage

The artifact includes a web fragment, if included in a Servlet 3.x container, it will automatically be added to the global web.xml

Other Spring usage

Anyone using the Artifact outside of a web container will need to get the StickyBootstrap object and call "start" on it (see the StickyBootStrapServlet for an example).

Notes

  • if you don't give a default value and the user doesnt provide a value, the initialization of your application will immediately fail (FAST FAIL)

Applications using: pretty much everything

nz.ac.auckland.common

University of Auckland - Group Applications

MIT Licensed Java/Groovy libraries we use

Versions

Version
3.5
3.4
3.3
3.2
3.1
2.6