Feature Toggles for Spring Boot applications with IBM Cloud App Configuration

Josephinejustin
2 min readFeb 20, 2022

IBM Cloud App Configuration is a centralized feature-management and configuration service. App Configuration helps developers effectively create, manage and toggle feature flags to control the releases. Use toggling of feature flags to instantly control the release of features and gradually roll out features to users or a subset of users. App Configuration also helps in you to easily promote feature flags across multiple environments of releases.

Spring Boot is popular Java-based enterprise grade framework. Spring boot provides a clean way to load your configuration in to the application using @ConfigurationProperties. It provides an easy way to externalize feature flags / configuration properties and helps to bind and validate these configurations.

In this tutorial, we will create a Spring Boot application which integrates with IBM Cloud App Configuration to load the features. For this tutorial we will use the base application which loads the configuration from properties file (application.yml).

Setup the IBM Cloud App Configuration instance

Create and Setup the IBM Cloud App Configuration service instance by following the steps here & here

Integrate Spring Boot application with IBM Cloud App Configuration

Define the App Configuration instance details in the application.yml file.

Add the App Configuration java SDK to pom.xml

Define the AppConfigurationFeatureFlagService.java which implements the FeatureFlagService

Initialize the App Configuration client by updating the constructor and the setup method

Now define entityAttibutes and call getCurrentValue of App Configuration SDK to get the value of the feature flags.

Similar to the above update the getFlashSale & getExclusiveOffers method

Complete application is available here

Run the application

Now you are all set to run the application. Open the application in the browser using http://localhost:8080. Since the feature flags are disabled initially, none of features are released. Enable the features in App Configuration dashboard to view the sections.

Exclusive offers section is available only to a set of users. Login as “alice@shoppers.com” (with password “pass”) to view the exclusive offers section. When logged in as “user” (with password “pass”) exclusive offers are not displayed as the user does not belong to the segmentation rule defined.

Conclusion

In this tutorial we used @ConfigurationProperties of Spring Boot to integrate with IBM Cloud App Configuration and released features only to a subset of users.

Resources

--

--