Tamaya Spring Integration (Extension Module)

Tamaya Spring is an extension module. Refer to the extensions documentation for further details.

What functionality this module provides ?

Tamaya Spring allows to use Tamaya as a configuration backend for Spring or Spring Boot:

  • Tamaya is added via a TamayaSpringPropertySource as an additional Spring PropertySource.

  • Finally org.apache.tamaya.integration.spring.SpringConfigInjectionPostProcessor implements a Bean PostProcessor, which adds all the fully fledged Tamaya configuration injection capabilities to Spring.


Both modules are based on Java 8, so they will run on Java 8 and beyond. The extension shown here works in Spring Framework as well as Spring Boot.


To benefit from Tamaya Spring integration add the following dependencies to your module:


Configuring Tamaya Spring Configuration

Tamaya leverages standard Spring functionality of Spring. To activate and configure Tamaya just add the corresponding Tamaya annotation to your Spring Configuration:

public class SampleWebFreeMarkerApplication {

	public static void main(String[] args) throws Exception {
		SpringApplication.run(SampleWebFreeMarkerApplication.class, args);


Extending or Overriding existing Spring Configuration

By default Tamaya is overriding any existing Spring configuration. But you can also configure Tamaya to extend Spring configuration only as follows:


Configuring your Beans

Similarly you can inject any kind of configuration as supported by Tamaya into your Spring managed beans. Hereby both, Spring injection and Tamaya injection mechanisms are supported:

@ConfigSection("app.root") // optional (1)
public class ConfiguredSpringBean {

    @Value("${application.message:Hello World}")  (2)
    private String message;

    private Environment env;

    @Config(value = "alternateMessage", required = false) (3)
    private String anotherMessage = "N/A";

    private String javaVersion;

    @Config(value={"number", "testNum", "[notavailable]"}, defaultValue="23") (4)(5)
    private int testNumber;

  1. You can configure default section prefixes. This is an optional feature.

  2. Tamaya does not require you to change your code. You can still work with Spring injection for your configuration, but Tamaya will override Spring configuration by default.

  3. You can also define entries as optional, which allows you to perform default inialization using Java idoms.

  4. Tamaya allows you to define an ordered list of key candidates, which are combined with the section prefix, if present, to the full keys. Keys added in brackets ([]) are interpreted as absolute keys, so the example above the key candidate list evaluates to app.root.number", "app.root.testNum", "notavailable".

  5. You can configure default values used, if no other value can be evaluated for the given keyset.

Summarizing you get all the nice features of Tamaya out of the box running with your Spring code.

For a full description of Tamaya’s injection API please refer to the corresponding documentation.

Disabling Tamaya Injection

If you dont like Tamaya injection, you can simply disable it: