We're currently in the process of upgrading our services to Spring Boot 3. One of them was relying on suffix-based content negotatiation (ie GET "/products/id.json" got the json, GET "/products/id.xml" the xml representation).
This was done using the mvc configuration
spring:
mvc:
contentnegotiation:
favor-path-extension: true
pathmatch:
matching-strategy: ant-path-matcher
use-registered-suffix-pattern: true
use-suffix-pattern: true
use-registered-suffix-pattern
was working before, I tried the use-suffix-pattern
as it is mentioned here. Both don't work anymore.
That link refers to Spring Boot 2.6 as enabling a legacy feature; I could not find any documentation about this for Spring Boot 3. Checking the WebMvcProperties
class which is the container of these properties, they seem to have been removed completely, only the matching-strategy remains.
Also, the ContentNegotiationConfigurer
's favorPathExtension
is deprecated, and the one in ContentNegotiationManagerFactoryBean
states "As there is no replacement for this method, in 5.2.x it is necessary to set it to false. In 5.3 the default changes to false and use of this property becomes unnecessary".
How is this unnecessary when we want to keep our interface downward compatible? What is the intended replacement for this? Do we need to use path matchers and add new get mappings, ie
@GetMapping(value = "/products/{id}.json", produces=JSON)
Product productJson(String id) { return service.product(id); }
@GetMapping(value = "/products/{id}.xml", service.produces=XML)
Product productXml(String id) { return service.product(id); }
@GetMapping(value = "/products/{id}", service.produces={XML, JSON})
Product product(String id) { return service.product(id); }
or am I missing something?