Home > Software design >  How to use content negotation format parameter in Spring WebFlux?
How to use content negotation format parameter in Spring WebFlux?

Time:03-03

spring.mvc.contentnegotiation.favor-parameter=true
spring.mvc.contentnegotiation.parameter-name=format

How can I use the content negotiation feature in spring webflux?

So that /request?format=json is possible beside Accept header.

CodePudding user response:

It works as follows, but don't know it that's the correct way:

@Configuration(proxyBeanMethods = false)
public class ReactiveWebFluxConfigurer {
    @Value("${spring.mvc.contentnegotiation.parameter-name}")
    private String formatName;

    @Bean
    public WebFluxConfigurer webFluxConfigurer() {
        return new WebFluxConfigurer() {
            @Override
            public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) {
                builder.parameterResolver().parameterName(formatName);
            }
        };
    }
}
  • Related