@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE]) @Import(DelegatingWebFluxConfiguration) class EnableWebFlux
Adding this annotation to an @Configuration
class imports the Spring Web Reactive configuration from WebFluxConfigurationSupport, e.g.:
@Configuration @EnableWebFlux @ComponentScan(basePackageClasses = MyConfiguration.class) public class MyConfiguration { }
To customize the imported configuration implement WebFluxConfigurer and override individual methods as shown below:
@Configuration @EnableWebFlux @ComponentScan(basePackageClasses = MyConfiguration.class) public class MyConfiguration implements WebFluxConfigurer { @Override public void addFormatters(FormatterRegistry formatterRegistry) { formatterRegistry.addConverter(new MyConverter()); } @Override public void configureMessageWriters(List<HttpMessageWriter<?>> messageWriters) { messageWriters.add(new MyHttpMessageWriter()); } }
Note: only one @Configuration
class may have the @EnableWebFlux
annotation to import the Spring WebFlux configuration. There can however be multiple @Configuration
classes implementing WebFluxConfigurer
in order to customize the provided configuration.
If WebFluxConfigurer does not expose some more advanced setting that needs to be configured consider removing the @EnableWebFlux
annotation and extending directly from WebFluxConfigurationSupport or DelegatingWebFluxConfiguration if you still want to allow WebFluxConfigurer instances to customize the configuration.
Author
Brian Clozel
Author
Rossen Stoyanchev
Since
5.0
See Also
WebFluxConfigurerWebFluxConfigurationSupport
EnableWebFlux()
Adding this annotation to an
To customize the imported configuration implement WebFluxConfigurer and override individual methods as shown below:
Note: only one If WebFluxConfigurer does not expose some more advanced setting that needs to be configured consider removing the |