Example Java Spring Boot application for CloudBees platform feature management

3 minute read

Use this example application to integrate with CloudBees platform and test feature management. After integrating, observe changes in the application UI as you update flag values in CloudBees platform.

In this example, the Rox SDK is already set up, and feature flags are implemented in the code.

Get started with the Java Spring Boot project

To get started with the springboot-fm-example project, follow these steps:

  1. Using Git, clone the springboot-fm-example repository to your local machine:

    git clone git@github.com:cloudbees-io/springboot-fm-example.git
  2. In your IDE, select File and open the cloned repository as a Gradle project. You will revisit this project in your IDE later, to run the application.

  3. Locate and copy the SDK key:

    1. Navigate to Feature management  Flags.

    2. Select an application.

    3. Select COPY next to the SDK key on the page.

      If no SDK key is available:

      1. Navigate to Feature management  Flags.

      2. Select install in the upper-right corner.

      3. Follow the installation instructions to complete the installation. The SDK key will appear once an application is linked to an environment.

      4. Close the installation instructions, and copy the SDK key.

  4. Reopen the project in your IDE.

  5. Add the SDK key to the application:

    1. Open the application.yaml file:

      src/main/resources/application.yaml
    2. Locate the following placeholder in the file, and replace it with your SDK key:

      key: "<Your CloudBees SDK key>"
  6. Save the updated file.

  7. Run the application in your IDE. For example:

    ./gradlew bootRun
  8. To view the application running, go to http://localhost:8080/api/demo in your web browser.

View the imported flags

Now that your application is running:

  1. In CloudBees platform, select Feature management.

  2. Select your example application to display the available flags as shown in the table below.

    Table 1. Feature flags in the example application
    Flag name Flag type Description

    showMessage

    Boolean

    Turns the message on or off.

    message

    String

    Sets the message text.

    fontSize

    Number

    Sets the message font size in pixels. The flag value has the following variations: 12, 16, or 24.

    fontColor

    String

    Sets the message font color. The flag value has the following variations: red, green, or blue.

    If no flags are displayed, verify that the environment-specific SDK key is correctly added to the project file: src/main/resources/application.yaml

    Save the file, and restart the application.

Apply changes to flags in the UI

  1. Select Feature management.

  2. Select the application.

  3. Select Vertical ellipsis next to the flag you want to configure.

  4. Select Configure.

  5. Select the Environment.

  6. Update a flag value and save your changes.

  7. Set the Configuration status to On.

  8. The updated flag value is reflected in the application display shortly.

Use the application with multiple SDK keys

Run multiple instances of the SDK in a single application, each with its own SDK key and environment. Each instance is fully isolated. Use this when you need to read or compare flags across environments without redeploying, support multi-tenant routing, or combine server-side and client-side evaluations in one application.

To use multiple SDK keys in the example Spring Boot application, follow these steps:

  1. Retrieve the SDK keys for the environments you’ll use.

  2. Initialize a separate SDK instance for each key.

  3. Decide how to route requests to instances (for example, by tenant, region, or environment selector).

  4. Perform register/fetch/stream setup on each instance as required by your SDK.

  5. Evaluate flags using the selected instance. Pass a consistent user/context object for accurate targeting.

  6. Tag logs or metrics by instance, and shut down instances you no longer need.

Documentation reference

For more information about using multiple SDK keys, refer to Manage multiple SDK keys in your application.

For installation details, refer to Install the SDK.