Node.js, PHP and APIs · Decision guide
Spring Boot returns 404 No static resource for a controller URL
Short answer
Spring MVC serves static files on /**, so a URL that no controller handles falls to ResourceHttpRequestHandler, which throws NoResourceFoundException: No static resource. Since Spring Framework 6.1 (Boot 3.2) that exception becomes a 404. List your mappings with /actuator/mappings, then fix the trailing slash, the controller's package or the file location. Applies to Boot 3.2 through 4.2.
Spring MVC maps its static-file handler to /**. A request that no controller claims falls through to that handler, which looks for a file, finds none, and throws NoResourceFoundException: No static resource .... Since Spring Framework 6.1 (Boot 3.2) that exception produces a 404. The message sounds like a missing file, but for an API call it usually means the controller never matched.
The path quoted in the message decides which fix applies, so start from it.
Find your case
- If the path in the message ends with a slash, such as users/Trailing slashes no longer match plain mappings.
- If the path is an API route and is missing from the mappings listThe controller was never registered.
- If the path names a file, such as css/app.css or uploads/photo.pngThe file is not in a folder Boot serves.
- If the only path is favicon.icoThe browser asked for it by itself.
List the mappings the app knows
Expose the actuator mappings endpoint and print every request path the running app has registered. Compare your URL with that list character by character.
Every registered request path
# application.properties
management.endpoints.web.exposure.include=health,mappings
curl -s http://localhost:8080/actuator/mappings | grep -o '{[A-Z]* \[[^]]*\]' | sortThis needs the actuator starter on the classpath. Remove the exposure setting again if the app is reachable from outside.
The URL ends in a slash
Spring Framework 6.0 turned trailing-slash matching off by default, and 7.0 removed the option. A handler declared as /api/users no longer answers /api/users/, so that request reaches the static handler and fails there.
Call the URL without the slash. If clients send both forms, list both paths on the handler, or register Spring's UrlHandlerFilter, which strips the slash before mapping. Boot adds any Filter bean to the embedded server.
Two ways to accept both forms
@GetMapping({"/api/users", "/api/users/"})
public List<User> users() { ... }
// or, for a whole tree of URLs:
@Bean
UrlHandlerFilter urlHandlerFilter() {
return UrlHandlerFilter.trailingSlashHandler("/api/**").wrapRequest().build();
}No controller is registered
If an API path is absent from the mappings list, Spring never created the controller bean. The usual reason is a controller in a package that is not at or below the package of the @SpringBootApplication class, so component scanning skips it. Classes in the default package, with no package line, cause trouble too.
Also check the annotation. A class-level @RequestMapping alone does not make a class a controller in Spring 6 and later; it needs @RestController or @Controller.
Controller below the application's package
// src/main/java/com/example/shop/ShopApplication.java
package com.example.shop;
// src/main/java/com/example/shop/web/UserController.java
package com.example.shop.web;
@RestController
@RequestMapping("/api/users")
public class UserController { ... }The file is outside the served folders
For a file URL, Boot looks in /static, /public, /resources and /META-INF/resources on the classpath. Files in src/main/resources/templates, outside the jar, or written by the app while it runs are not there. Put bundled files under src/main/resources/static with the same folder path as the URL. For files saved at runtime, map a URL prefix to a folder on disk.
Serve a folder on disk under /uploads
@Configuration
public class UploadsConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/uploads/**")
.addResourceLocations("file:/var/app/uploads/");
}
}favicon.ico
A No static resource favicon.ico line comes from the browser. When a page has no icon link, browsers fetch /favicon.ico on their own, and Boot answers only if that file sits in a static location. API calls are not affected. Add an icon file to the static folder, or ignore the line in a pure API.
Add an icon
cp my-icon.ico src/main/resources/static/favicon.icoMake the real cause visible next time
- In an API-only app set
spring.mvc.static-path-patternto/resources/**, so a missing route raisesNoHandlerFoundExceptionand the log names the real problem. - Add a MockMvc test per controller that calls its real URL, so a moved package fails the build.
- If the path is in the mappings, has no slash issue and still returns this 404, look for a servlet path, proxy prefix or security filter that rewrites the URL before Spring MVC sees it.
In short
- The static handler is only where unmatched requests end up.
- Read the path in the message: slash, API route, file, or favicon.
/actuator/mappingsshows what the app really registered.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.