org.springframework.web.reactive.config

Annotation Type EnableWebFlux



  • @Retention(value=RUNTIME)
     @Target(value=TYPE)
     @Documented
     @Import(value=DelegatingWebFluxConfiguration.class)
    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:

     @Configuration
     @EnableWebFlux
     @ComponentScan(basePackageClasses = MyConfiguration.class)
     public class MyConfiguration {
     }
     

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

     @Configuration
     @EnableWebFlux
     @ComponentScan(basePackageClasses = MyConfiguration.class)
     public class MyConfiguration implements WebFluxConfigurer {
    
               @Override
               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.

    Since:
    5.0
    Author:
    Brian Clozel, Rossen Stoyanchev
    See Also:
    WebFluxConfigurer, WebFluxConfigurationSupport, DelegatingWebFluxConfiguration