@Retention(value=RUNTIME) @Target(value=TYPE) @Documented @Import(value=DelegatingWebFluxConfiguration.class) public @interface EnableWebFlux
@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.
WebFluxConfigurer
,
WebFluxConfigurationSupport