The document discusses configuration in Java applications. It provides an overview of configuration concepts, the configuration lifecycle, popular configuration runtime systems like Apache Tamaya and Microprofile Config, and how to access and manage configuration data programmatically. It also describes configuration backends that connect configuration systems to different data sources, as well as extension services that provide additional functionality.
2. 2
Agenda
• What is Configuration?
• Lifecycle and Runtimes
• Backends
• Configuration Services
• How to use it in your projects?
26.06.2019 Configuration in Java2
3. Anatole Tresch
Principal Consultant, Trivadis AG (Switzerland)
Spec Lead JSR 352 (Money and Currency)
JSR 382 EG Member
PPMC Member Apache Tamaya
@atsticks
anatole@apache.org
anatole.tresch@trivadis.com
3
About me
26.06.2019 Configuration in Java3
5. 5
Wikipedia: Configuration
“In computing, configuration defines parameters and settings that control behavior
of some computer programs. They are used for user applications, server processes
and operating system settings and may change during runtime.”
System
Input Output
Config
26.06.2019 Configuration in Java5
6. 6
Wikipedia: Configuration Files
“In computing, configuration files (or config files) are files used to configure the
parameters and initial settings for some computer programs. They are used for user
applications, server processes and operating system settings.”
26.06.2019 Configuration in Java6
10. 10
Configuration Files: properties
• No explicit support for
hierarchies, lists etc.
• Pure i18n support
• Pure Multiline support
26.06.2019 Configuration in Java10
14. 14
Like HJSON, but even simpler
https://github.com/lightbend/config
Configuration Files: hocon
{
a : A
b : B
c : C
d {
o: O
p: P
}
}
26.06.2019 Configuration in Java14
16. 16
Configuration Lifecycle
• Development
• Build time
• Deployment time
• Runtime A Configuration Runtime System must
support all of them!
26.06.2019 Configuration in Java16
17. Configuration Runtime
• A programmatic model of Configuration Data
• A programmatic API to access Configuration Data
• An SPI for extending and customizing
• Optional:
• A predefined lifecycle of configuration data
• Integration with other frameworks, e.g.
Spring, JakartaEE, OSGI, plain Java, …
26.06.2019 Configuration in Java17
20. Microprofile
• Part of MicroProfile.io project
• JSR 382 Code has been moved here
• Minimum viable solution:
• Configuration can live outside of an application.
• Ready for Microservice and container environments.
• Different Locations and Formats
• Dynamic change is possible.
• A @ConfigProperty annotation for CDI (incl. default values).
• String/String key/value, types through Converters
• A Config API to function without CDI.
• Current Release 1.3 (part of MP 2.2)
20
https://github.com/eclipse/microprofile-config
26.06.2019 Configuration in Java20
21. 21
Apache Tamaya
• Result of first Standardization Attempt in 2013
• Minimum viable solution:
• Basically similar to JSR 382/Microprofile
• Full SE API
• Mature
• Tree value model for more powerful type, conversion & filtering mechanisms
• With modular extensions:
• A @Config annotation for injection (works with Spring, CDI and more)
• Multiple formats (props, xml, json, hjson, yaml, hocon, ini)
• Integration with Spring, OSGI, Camel, Vertx and more
• Metaconfig, Documentation (sandbox)
http://tamaya.apache.org
26.06.2019 Configuration in Java21
23. 23
Helidon
• Part of Oracle’s Microservice Framework
• Authors are the same as in JSR discussion of 2016
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config</artifactId>
<version>version-of-config-you-are-using</version>
</dependency>
https://helidon.io/
33. Configuration Data - Builders
Apache Tamaya
• Tamaya has also functonality for removing/reordering of existing SPI artifacts.
• Filters are not supported by the JSR as of now.
26.06.2019 Configuration in Java33
35. 35
Configuration Backends (SPI) – Basic Idea
Config Runtime
Backends
Configuration Data
(Files, Servers etc.)
«Backends are are the
adapters between the
config system and your
Configuration Data»
26.06.2019 Configuration in Java35
41. Example Service: Placeholder resolution
Apache Tamaya
• When the tamaya-resolver
extension is installed, resolution
is transparent.
26.06.2019 Configuration in Java41
42. Example Service: Functional Operators
• Filtering and Printing with
the tamaya-functions extension.
26.06.2019 Configuration in Java42
45. Design in 120 Seconds...
• Tamaya
ConfigurationContext
PropertyFilters
ConfigSources
Microprofile
ServiceContextManager
PropertySources
String Value
Typed Value
ConfigProvider
ServiceContext
PropertyValue
Tamaya
Typed Value
PropertyValue:
- Simple
- Array
- Map
+ Metadata
PropertyValue
PropertySourceProvider
ConfigSourceProvider
<create>
<create>
ConfigurationProviderSpi
ConfigProviderResolver
+ ConversionContext
+ FilterContext
ConfigAccessor
26.06.2019 Configuration in Java45
46. Configuration SPI – Tamaya Value Tree
• Matches structures as defined by yaml, json, xml configuration files.
• Allows complex mappings, e.g. multi-value based collections and complex
custom types
• Mapping to properties still possible (and OOTB supported).
PropertyValue
+ value: String
+ metadata: Map<String,String>
ObjectValue
+ fields: Map<String,PropertyValue>
ListValue
+ children: List<PropertyValue>
26.06.2019 Configuration in Java46
47. Configuration SPI – Type Converters
Microprofile
26.06.2019 Configuration in Java47
48. Configuration SPI – Type Converters
Apache Tamaya
• Tamaya’s PropertyConverters have additional access to a ConversionContext
26.06.2019 Configuration in Java48
50. 50
1. Add Dependencies to your Project
<dependency>
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>…</version>
</dependency>
Core API & Implementation
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-spring</artifactId>
<version>…</version>
</dependency>
Basic Extensions Needed for Spring Support
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-functions</artifactId>
<version>…</version>
</dependency>
• Current version: 0.4-incubating-SNAPSHOT
• Tamaya only, for Microprofile also add Tamaya‘s
microprofile extension module
• Dont forget to use the Apache Snapshot Repo:
https://repository.apache.org/content/repositor
ies/snapshots
26.06.2019 Configuration in Java50
55. 55
Recap: Configuration in Java
⚫ Configuration is a «hot» topic
⚫ JSR 382 stopped
⚫ Work will continue at Microprofile.io
⚫ Microprofile API is very puristic.
⚫ Apache Tamaya provides all features you will need and supports all major runtimes.
⚫ Apache Tamaya is ready to use!
26.06.2019 Configuration in Java55