Message-ID: <282045094.2347.1427603606653.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2346_221575456.1427603606653" ------=_Part_2346_221575456.1427603606653 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
ConfigSlurper is a utility = class within Groovy for writing properties file like scripts for performing= configuration. Unlike regular Java properties files ConfigSlurper scripts = support native Java types and are structured like a tree.
Below is an example of how you could configure Log4j with a ConfigSlurpe= r script:
To load this into a readable config you can do:
As you can see from the example above you can navigate the config using = dot notation and the return values are Java types like strings and booleans= .
You can also use scoping in config scripts to avoid repeating yourself. = So the above config could also be written as:
You can convert ConfigSlurper configs to and from Java properties files.= For example:
You can merge config objects so if you have multiple config files and wa= nt to create one central config object you can do:
You can serialize a config object to disk. Each config object implements= the groovy.lang.Writable interface that allows you to write out the config= to any java.io.Writer:
The ConfigSlurper class has a special constructor other than t= he default constructor that takes an "environment" parameter. Thi= s special constructor works in concert with a property setting called envir= onments. This allows a default setting to exist in the property file that c= an be superceded by a setting in the appropriate environments closure. This= allows multiple related configurations to be stored in the same file.
Given this groovy property file:
Here is the demo code that exercises this configuration:
Note: the environments closure is not directly parsable. Without using t= he special environment constructor the closure is ignored.
The value of the environment constructor is also available in the config= uration file, allowing you to build the configuration like this: