Affected Version: Spring Web 5.3.1
.
Deprecation note on ContentNegotiationManagerFactoryBean:setFavorPathExtension(boolean) is misleading.
https://github.com/spring-projects/spring-framework/blob/6a0377b1a257a10ddc5735472094e649c14e2572/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java#L164-L177
It states that As there is no replacement for this method, in 5.2.x it is necessary to set it to {@code false}. In 5.3 the default changes to {@code false} and use of this property becomes unnecessary.
But the default value of favorPathExtension
still is true
.
https://github.com/spring-projects/spring-framework/blob/6a0377b1a257a10ddc5735472094e649c14e2572/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java#L111
If the property is not used, path extension will be favored indicating that a call to setFavorPathExtension(false)
is still necessary, contrary to the deprecation note.
Comment From: rstoyanchev
I believe the intent was to turn off path extensions completely in 5.3, both for content-type and for suffix pattern matching. This is also based on the fact that a deprecation on a method does not mean much if you must use it to achieve the recommended configuration. I'll take a closer look at correcting this in 5.3.2.
Comment From: rstoyanchev
I have changed the default setting of favorPathExtension
so that now both path extensions are not checked and suffix pattern matching is not used by default.
For applications that need to revert back for the time being:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(true);
}
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer
// ...
.setUseSuffixPatternMatch(true);
}
}
<mvc:annotation-driven content-negotiation-manager="mvcContentNegotiationManager" />
<mvc:path-matching suffix-pattern="true"/>
</mvc:annotation-driven>
<bean id="mvcContentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="true"/>
</bean>