Skip to content

Spring Boot

FF4j provides Spring Boot starters that help integrate FF4j into a Spring Boot application. The starters provide auto-configuration for FF4j, making it easy to set up and use. With the starters, you can easily enable or disable features in your application based on the configuration of FF4j.

Overview

FF4j provides two Spring Boot starters:

Feature ff4j-spring-boot-starter-webmvc ff4j-spring-boot-starter-webflux
RESTful APIs
OpenAPI Documentation
Web Console

Sample

With ff4j-spring-boot-starter-webmvc

Info

The complete sample is available in the ff4j-spring-boot-starter-webmvc-sample

Add the dependency ff4j-spring-boot-starter-webmvc

pom.xml
<dependency>
  <groupId>org.ff4j</groupId>
  <artifactId>ff4j-spring-boot-starter-webmvc</artifactId>
  <version>${ff4j.version}</version>
</dependency>

Configure FF4j

FF4JConfiguration.kt
import org.ff4j.FF4j
import org.ff4j.conf.XmlParser
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class FF4JConfiguration {
  @Bean
  fun getFF4J(): FF4j = FF4j(XmlParser(), "ff4j-features.xml")
}

Run the application with mvn spring-boot:run and access the FF4j web console at http://localhost:8080/ff4j-console

With ff4j-spring-boot-starter-webflux

Info

The complete sample is available in the ff4j-spring-boot-starter-webflux-sample

Add the dependency ff4j-spring-boot-starter-webflux

pom.xml
<dependency>
  <groupId>org.ff4j</groupId>
  <artifactId>ff4j-spring-boot-starter-webflux</artifactId>
  <version>${ff4j.version}</version>
</dependency>

Configure FF4j

FF4JConfiguration.kt
import org.ff4j.FF4j
import org.ff4j.conf.XmlParser
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class FF4JConfiguration {
  @Bean
  fun getFF4J(): FF4j = FF4j(XmlParser(), "ff4j-features.xml")
}

Run the application with mvn spring-boot:run and access the FF4j web api at http://localhost:8080/swagger-ui/index.html