Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

November Discount Launch 2022 – Top
We’re finally running a Black Friday launch. All Courses are 30% off until the end of this week:


NPI – Lightrun – Spring (partner)

We rely on other people’s code in our own work. Every day. It might be the language you’re writing in, the framework you’re building on, or some esoteric piece of software that does one thing so well you never found the need to implement it yourself.

The problem is, of course, when things fall apart in production - debugging the implementation of a 3rd party library you have no intimate knowledge of is, to say the least, tricky. It’s difficult to understand what talks to what and, specifically, which part of the underlying library is at fault.

Lightrun is a new kind of debugger.

It's one geared specifically towards real-life production environments. Using Lightrun, you can drill down into running applications, including 3rd party dependencies, with real-time logs, snapshots, and metrics. No hotfixes, redeployments, or restarts required.

Learn more in this quick, 5-minute Lightrun tutorial:

>> The Essential List of Spring Boot Annotations and Their Use Cases

 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.

November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until the end of this week:


Persistence footer banner
Comments are closed on this article!