Annotation 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
 public class MyConfiguration {
 }
 

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

 @Configuration
 @EnableWebFlux
 @ComponentScan
 public class MyConfiguration implements WebFluxConfigurer {

     @Autowired
     private ObjectMapper objectMapper;

     @Override
     public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
         configurer.defaultCodecs().jackson2JsonEncoder(
             new Jackson2JsonEncoder(objectMapper)
         );
         configurer.defaultCodecs().jackson2JsonDecoder(
             new Jackson2JsonDecoder(objectMapper)
         );
     }

     // ...
 }
 

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: