StaffCoder
Spring Boot
Spring BootSpring Boot 4.1Java 25
12 modules · 48 challengesSign up
Module 1 · Beans & Dependency Injection

Feature Flag Bean Registry

easyBean DeclarationExternalized Configuration80%4 of 5 solved

Problem statement

Build a REST API that reports feature flags declared as beans and configured from properties.

Requirements

FlagConfig

There are three feature flags, darkMode, betaSearch, and newCheckout, each with a default value in application.properties under its own property key.

  • Turn this class into a configuration class and declare each of the three flags as a separate bean in it
  • The FeatureFlag type is not a scanned component, so component scanning will not create these beans; each flag must be declared explicitly as a bean in this class
  • For each flag, read its default enabled state from its property and create a FeatureFlag whose name is the flag name and whose enabled state is that property value:
    • darkMode reads property flags.dark-mode
    • betaSearch reads property flags.beta-search
    • newCheckout reads property flags.new-checkout
  • If a property is missing, the flag defaults to disabled

FlagController

Collect the declared FeatureFlag beans through the constructor, then implement the endpoint.

GET /flags

  • Return 200 OK with a JSON object mapping every flag's name to its boolean enabled state
  • Each flag's reported state is whatever its property resolves to, so changing a property value changes the response with no code change

Sample Requests & Responses

Expand to view details on sample requests and responses.

GET /flags

Response (200 OK):

{
  "darkMode": true,
  "betaSearch": false,
  "newCheckout": false
}

More in Beans & Dependency Injection

See the module
Coffee Shop Order PrinterThis problem covers connecting the parts of a coffee shop ordering app so each one is handed what it needs, instead of building it itself.44%36 of 81 solvedeasyTemperature Unit Provider SwitcherThis problem covers registering two temperature converters and telling Spring which one to use by default and which one to hand over when it is asked for by name.59%10 of 17 solvedeasyNotification Dispatch SelectorThis problem covers sending a message through the channel the user picked, and what to fall back to when the channel isn't recognized.75%3 of 4 solvedeasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.