Scrivio Interview library
DebuggingIntermediate5 min read · updated 12 November 2026

A request to /api/orders/ returns 404 after an upgrade to Spring Boot 3, while /api/orders works. What changed?

Spring Framework 6, the base of Spring Boot 3, no longer treats /api/orders/ as a match for a mapping of /api/orders: trailing slash matching is off by default. The fix is to map both paths explicitly where they must both work, or to redirect or rewrite the trailing-slash form in a filter or at the proxy, and to update clients to use the canonical path. The same release also dropped suffix pattern matching, so /orders.json no longer reaches a /orders mapping either.

Why this question is asked

Upgrade bugs like this one are frustrating because nothing in the code changed, the tests for /api/orders pass, and still a client that has worked for years starts getting 404s. Interviewers ask it because it checks whether we know what changed in path matching between Spring 5 and 6 and how to handle it without reintroducing ambiguity. In this answer, we will recap how path matching worked before, reproduce the 404, explain why Spring changed the default, go through the fixes, and cover the related suffix change.

1A Quick Recap of Path Matching Before Spring 6

When a request arrives, Spring MVC compares its path with the patterns in @RequestMapping annotations. Up to Spring Framework 5.3, this comparison had a convenience called trailing slash match, turned on by default: a mapping for /api/orders also matched /api/orders/. There was a second convenience, suffix pattern matching, which let /api/orders.json reach the same method and chose JSON from the extension.

These made Spring forgiving, but they also meant that one method answered to several URLs that were really different paths, which caused confusion and security problems.

2Reproducing the 404

Here is the same controller before and after the upgrade.

Java
@RestController
@RequestMapping("/api")
class OrderController {
@GetMapping("/orders")
List<OrderDto> list() { return service.findAll(); }
}
// Spring Boot 2.7 (Spring Framework 5.3)
// GET /api/orders -> 200
// GET /api/orders/ -> 200 (trailing slash matched)
// Spring Boot 3.x (Spring Framework 6)
// GET /api/orders -> 200
// GET /api/orders/ -> 404 (No mapping, or NoResourceFoundException in newer versions)

Notice that the 404 comes from the mapping step, before any of our code runs, which is why no log line from the controller appears.

3Why Spring Changed the Default

The main reason is security and consistency. Paths with and without a trailing slash are different URLs, and other parts of the system may treat them differently. A security rule written for /api/admin might not protect /api/admin/ in one component while the controller still serves it, and caches, proxies and gateways may see two resources where Spring sees one. Making matching exact removes that class of mismatch.

In Spring Framework 6 the option to restore the old behaviour, setUseTrailingSlashMatch(true) on PathMatchConfigurer, still exists but is deprecated, and it is expected to disappear in a later generation, so check your version and treat it only as a short bridge.

What matches /api/orders
Request pathSpring Framework 5.3 defaultSpring Framework 6 default
/api/ordersmatchmatch
/api/orders/match (trailing slash)404
/api/orders.jsonmatch (suffix pattern, if enabled)404

4Fix 1: Map Both Paths Explicitly

When a few endpoints must accept both forms, we can say so in the mapping. This is explicit, visible in code review, and limited to the endpoints that need it.

Java
@GetMapping({"/orders", "/orders/"})
List<OrderDto> list() { return service.findAll(); }
// GET /api/orders/ -> 200

The downside is that it spreads across controllers if many endpoints are affected, and security rules must cover both paths too.

5Fix 2: Redirect or Rewrite in a Filter or the Proxy

A central fix handles all endpoints the same way. We can redirect the trailing-slash form to the canonical path, which tells clients the right URL, or rewrite it internally, which keeps old clients working silently. Spring Framework 6.2 added UrlHandlerFilter for exactly this; check your version for its exact API. On older versions, a small custom filter or a rule at the reverse proxy or gateway does the same.

Java
@Bean
FilterRegistrationBean<UrlHandlerFilter> trailingSlashFilter() {
UrlHandlerFilter filter = UrlHandlerFilter
.trailingSlashHandler("/api/**").redirect(HttpStatus.PERMANENT_REDIRECT) // 308 to /api/orders
.build();
return new FilterRegistrationBean<>(filter);
}
// GET /api/orders/ -> 308 Location: /api/orders -> 200
// or, to keep old clients working without a round trip:
// .trailingSlashHandler("/api/**").wrapRequest() // the request is seen as /api/orders

Notice the 308 status rather than 301. A 308 Permanent Redirect keeps the method and the body, so a POST to /api/orders/ is repeated as a POST, while many clients turn a 301 POST into a GET. Placing this before Spring Security also means security rules only ever see canonical paths.

6Updating Clients and the Suffix Change

The filter is a bridge, not the goal. The long-term fix is that clients call the canonical path, so we log the requests that hit the redirect, find the clients by their user agent or client id, and ask them to update, then remove the bridge after an agreed date.

The same release removed suffix pattern matching. A client calling /api/orders.json to get JSON now gets a 404. The replacement is content negotiation through the Accept header, Accept: application/json, or, if a URL-based choice is really needed, an explicit query parameter such as ?format=json configured in the content negotiation settings, or an explicit mapping of /orders.json where it must keep working.

7Follow-up questions

Can we just turn trailing slash matching back on?

On Spring Framework 6 we can, with configurer.setUseTrailingSlashMatch(true) in a WebMvcConfigurer, but the method is deprecated, it brings back the mismatch risk between security rules and handlers, and it may be removed in a future version. It is acceptable as an emergency patch to stop the 404s while a filter-based redirect and client updates are rolled out, and it should come with a ticket to remove it.

Why do the tests pass after the upgrade?

Because they call the canonical path. A useful lesson is to add tests for the URLs real clients use, taken from access logs, especially before framework upgrades.

Does WebFlux behave the same way?

Yes, Spring WebFlux also stopped matching trailing slashes by default in version 6, and Spring Framework 6.2 offers a reactive UrlHandlerFilter as well; check your version.

8Conclusion

In this answer, we saw that Spring Framework 6 made path matching exact, so /api/orders/ no longer matches a mapping for /api/orders, and that suffix pattern matching such as /orders.json was removed in the same release. The change exists to stop mismatches between security rules, proxies and handlers. We fixed the 404 by mapping both paths where needed or by redirecting or rewriting in a filter or at the proxy, with a 308 to keep methods, and planned to move clients to the canonical path.

What to say in the interviewAbout 80 seconds aloud

Open with

The cause is a default change in Spring Framework 6, which Spring Boot 3 is built on. In 5.3 and earlier, trailing slash matching was on, so a mapping for /api/orders also matched /api/orders/.

Then, if they want more

In 6 it is off, so the trailing-slash URL simply has no mapping and returns 404 before any controller code runs. Spring changed it because the two are different URLs, and treating them as one caused mismatches, for example a security rule matching one form while the controller served both. There are a few fixes.

If only a couple of endpoints need both, I map both paths explicitly in the annotation. If it is widespread, I handle it centrally: redirect the trailing-slash form to the canonical path with a 308, which keeps the HTTP method, or rewrite the request internally. Spring Framework 6.2 has UrlHandlerFilter for that, and a gateway or proxy rule works too.

The deprecated setUseTrailingSlashMatch(true) can be an emergency bridge, but I would not keep it. Long term, clients should call the canonical path, so I would log redirected requests and contact those clients. I would also check for the related change: suffix pattern matching was removed, so URLs like /orders.json now 404 and should use the Accept header instead.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6, Spring Boot 3, Spring Framework 5, Spring Boot 2.7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A request to /api/orders/ returns 404 after an upgrade to Spring Boot 3, while...": https://scrivio-interview-library.netlify.app/spring-boot/mvc-architecture/e5269c4435/