Issue
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.
Solution
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);
//if you want, add additional fallback to Accept header if format param is missing
builder.headerResolver();
}
};
}
}
Answered By - membersound
Answer Checked By - Pedro (JavaFixing Volunteer)