Annotation Type EnableWebFlux

  • @Retention(value=RUNTIME)
    public @interface EnableWebFlux
    Adding this annotation to an @Configuration class imports the Spring WebFlux configuration from WebFluxConfigurationSupport that enables use of annotated controllers and functional endpoints.

    For example:

     @ComponentScan(basePackageClasses = MyConfiguration.class)
     public class MyConfiguration {

    To customize the imported configuration, implement WebFluxConfigurer and one or more of its methods:

     @ComponentScan(basePackageClasses = MyConfiguration.class)
     public class MyConfiguration implements WebFluxConfigurer {
               public void configureMessageWriters(List<HttpMessageWriter<?>> messageWriters) {
             messageWriters.add(new MyHttpMessageWriter());
               // ...

    Only one @Configuration class should have the @EnableWebFlux annotation in order to import the Spring WebFlux configuration. There can however be multiple @Configuration classes that implement WebFluxConfigurer that customize the provided configuration.

    If WebFluxConfigurer does not expose some setting that needs to be configured, consider switching to an advanced mode by removing the @EnableWebFlux annotation and extending directly from WebFluxConfigurationSupport or DelegatingWebFluxConfiguration -- the latter allows detecting and delegating to one or more WebFluxConfigurer configuration classes.

    Brian Clozel, Rossen Stoyanchev
    See Also:
    WebFluxConfigurer, WebFluxConfigurationSupport, DelegatingWebFluxConfiguration