Spring Top

Get started with Spring 5 and Spring Boot 2, through the reference Learn Spring course:

Persistence top

Get started with Spring Data JPA through the reference Learn Spring Data JPA course:


 1. Overview

The Netflix Archaius offers libraries and functionality for connecting to many data sources.

In this tutorial, we'll learn how to get configurations:

  • Using the JDBC API to connect to a database
  • From configurations stored in a DynamoDB instance
  • By configuring Zookeeper as a dynamic distributed configuration

For the introduction to Netflix Archaius, please have a look at this article.

2. Using Netflix Archaius with a JDBC Connection

As we explained in the introductory tutorial, whenever we want Archaius to handle the configurations, we'll need to create an Apache's AbstractConfiguration bean.

The bean will be automatically captured by the Spring Cloud Bridge and added to the Archaius' Composite Configuration stack.

2.1. Dependencies

All the functionality required to connect to a database using JDBC is included in the core library, so we won't need any extra dependency apart from the ones we mentioned in the introductory tutorial:



We can check Maven Central to verify we're using the latest version of the starter library.

2.2. How to Create the Configuration Bean

In this case, we'll need to create the AbstractConfiguration bean using a JDBCConfigurationSource instance.

To indicate how to obtain the values from the JDBC database, we'll have to specify:

  • a javax.sql.Datasource object
  • a SQL query string that will retrieve at least two columns with the configurations' keys and its corresponding values
  • two columns indicating the properties keys and values, respectively

Let's go ahead then an create this bean:

DataSource dataSource;

public AbstractConfiguration addApplicationPropertiesSource() {
    PolledConfigurationSource source =
      new JDBCConfigurationSource(dataSource,
        "select distinct key, value from properties",
    return new DynamicConfiguration(source, new FixedDelayPollingScheduler());

2.3. Trying It Out

To keep it simple and still have an operative example, we'll set up an H2 in-memory database instance with some initial data.

To achieve this, we'll first add the necessary dependencies:


Note: we can check the latest versions of the h2 and the spring-boot-starter-data-jpa libraries in Maven Central.

Next, we'll declare the JPA entity that will contain our properties:

public class Properties {
    private String key;
    private String value;

And we'll include a data.sql file in our resources to populate the in-memory database with some initial values:

insert into properties
values('baeldung.archaius.properties.one', 'one FROM:jdbc_source');

Finally, to check the value of the property at any given point, we can create an endpoint that retrieves the values managed by Archaius:

public class ConfigPropertiesController {

    private DynamicStringProperty propertyOneWithDynamic = DynamicPropertyFactory
      .getStringProperty("baeldung.archaius.properties.one", "not found!");

    public Map<String, String> getPropertiesFromDynamic() {
        Map<String, String> properties = new HashMap<>();
        properties.put(propertyOneWithDynamic.getName(), propertyOneWithDynamic.get());
        return properties;

If the data changes at any point, Archaius will detect it at runtime and will start retrieving the new values.

This endpoint can be used in the next examples as well, of course.

3. How to Create a Configuration Source Using a DynamoDB Instance

As we did in the last section, we'll create a fully functional project to analyze properly how Archaius manages properties using a DynamoDB instance as a source of configurations.

3.1. Dependencies

Let's add the following libraries to our pom.xml file:


We can check Maven Central for the latest dependencies versions, but for the archaius-aws one, we suggest sticking to the version supported by the Spring Cloud Netflix library.

The aws-java-sdk-dynamodb dependency will allow us to set up the DynamoDB client to connect to the database.

With the spring-data-dynamodb library, we will set up the DynamoDB repository.

And lastly, we'll use the archaius-aws library to create the AbstractConfiguration.

3.2. Using DynamoDB as a Configuration Source

This time, the AbstractConfiguration will be created using a DynamoDbConfigurationSource object:

AmazonDynamoDB amazonDynamoDb;

public AbstractConfiguration addApplicationPropertiesSource() {
    PolledConfigurationSource source = new DynamoDbConfigurationSource(amazonDynamoDb);
    return new DynamicConfiguration(
      source, new FixedDelayPollingScheduler());

By default Archaius searches for a table named ‘archaiusProperties', containing a ‘key' and a ‘value' attributes in the Dynamo database to use as a source.

If we want to override those values, we'll have to declare the following system properties:

  • com.netflix.config.dynamo.tableName
  • com.netflix.config.dynamo.keyAttributeName
  • com.netflix.config.dynamo.valueAttributeName

3.3. Creating a Fully Functional Example

As we did in this DynamoDB guide, we'll start by installing a local DynamoDB instance to test the functionality easily.

We'll also follow the instructions of the guide to create the AmazonDynamoDB instance that we ‘autowired' previously.

And to populate the database with some initial data, we'll first create a DynamoDBTable entity to map the data:

@DynamoDBTable(tableName = "archaiusProperties")
public class ArchaiusProperties {

    private String key;

    private String value;

    // ...getters and setters...

Next, we'll create a CrudRepository for this entity:

public interface ArchaiusPropertiesRepository extends CrudRepository<ArchaiusProperties, String> {}

And finally, we'll use the repository and the AmazonDynamoDB instance to create the table and insert the data afterward:

private ArchaiusPropertiesRepository repository;

AmazonDynamoDB amazonDynamoDb;

private void initDatabase() {
    DynamoDBMapper mapper = new DynamoDBMapper(amazonDynamoDb);
    CreateTableRequest tableRequest = mapper
    tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1L, 1L));
    TableUtils.createTableIfNotExists(amazonDynamoDb, tableRequest);

    ArchaiusProperties property = new ArchaiusProperties("baeldung.archaius.properties.one", "one FROM:dynamoDB");

We can call this method right before creating the DynamoDbConfigurationSource.

We're all set now to run the application.

4. How to Set up a Dynamic Zookeeper Distributed Configuration

As we've seen before on out introductory Zookeeper article, one of the benefits of this tool is the possibility of using it as a distributed configuration store.

If we combine it with Archaius, we end up with a flexible and scalable solution for configuration management.

4.1. Dependencies

Let's follow the official Spring Cloud's instructions to set up the more stable version of Apache's Zookeeper.

The only difference is that we only need a part of the functionality provided by Zookeeper, thus we can use the spring-cloud-starter-zookeeper-config dependency instead of the one used in the official guide:


Again, we can check the latest versions of spring-cloud-starter-zookeeper-config and zookeeper dependencies in Maven Central.

Please make sure to avoid the zookeeper beta versions.

4.2. Spring Cloud's Automatic Configuration

As it's explained in the official documentation, including the spring-cloud-starter-zookeeper-config dependency is enough to set up the Zookeeper property sources.

By default, only one source is autoconfigured, searching properties under the config/application Zookeeper node. This node is therefore used as a shared configuration source between different applications.

Additionally, if we specify an application name using the spring.application.name property, another source is configured automatically, this time searching properties in the config/<app_name> node.

Each node name under these parent nodes will indicate a property key, and their data will be the property value.

Luckily for us, since Spring Cloud adds these property sources to the context, Archaius manages them automatically. There is no need to create an AbstractConfiguration programmatically.

4.3. Preparing the Initial Data

In this case, we'll also need a local Zookeeper server to store the configurations as nodes. We can follow this Apache's guide to set up a standalone server that runs on port 2181.

To connect to the Zookeeper service and create some initial data, we'll use the Apache's Curator client:

public class ZookeeperConfigsInitializer {

    CuratorFramework client;

    public void appReady(ApplicationReadyEvent event) throws Exception {
        if (client.checkExists().forPath("/config/application/baeldung.archaius.properties.one") == null) {
              "one FROM:zookeeper".getBytes());
        } else {
              "one FROM:zookeeper".getBytes());

    private void createBaseNodes() throws Exception {
        if (client.checkExists().forPath("/config") == null) {
        if (client.checkExists().forPath("/config/application") == null) {

We can check the logs to see the property sources to verify that Netflix Archaius refreshed the properties once they change.

5. Conclusion

In this article, we've learned how we can setup advanced configuration sources using Netflix Archaius. We have to take into consideration that it supports other sources as well, such as Etcd, Typesafe, AWS S3 files, and JClouds.

As always, we can check out all the examples in our Github repo.

Spring bottom

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

Persistence bottom
Get started with Spring Data JPA through the reference Learn Spring Data JPA course: >> CHECK OUT THE COURSE
Comments are closed on this article!