How to Fix the “No Static Resource” Error After Upgrading Spring Boot 2.x to 3.x

After migrating a Spring Boot application from 2.x to 3.x, the “No static resource” error often appears because of Jakarta EE package changes and altered static‑resource configuration, and this guide walks you through the root causes, configuration updates, code changes, and practical debugging steps to resolve it.

Ray's Galactic Tech
Ray's Galactic Tech
Ray's Galactic Tech
How to Fix the “No Static Resource” Error After Upgrading Spring Boot 2.x to 3.x

Background

Upgrading a Spring Boot project from version 2.x to 3.x introduces Jakarta EE, which changes package names from javax.* to jakarta.* and may alter static‑resource handling. These changes frequently cause the runtime error No static resource when the application cannot locate static files.

Key Differences to Check

Servlet API : replace imports of javax.servlet with jakarta.servlet.

Static resource path : the default locations ( classpath:/static/, classpath:/public/) stay the same, but the property name may need explicit configuration via spring.web.resources.static-locations.

CORS configuration : .addAllowedOrigin("*") is deprecated; use .addAllowedOriginPattern("*") instead.

Custom WebMvc configuration : when providing a WebMvcConfigurer, you must explicitly add resource handlers for static files and WebJars.

Step‑by‑step Troubleshooting

Update Servlet imports Search the whole codebase for javax.servlet and replace it with jakarta.servlet .

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

Explicitly configure static‑resource locations Add the following to your configuration files (both application.properties and application.yml are shown):

# application.properties
spring.web.resources.static-locations=classpath:/static/
spring.mvc.static-path-pattern=/**
# application.yml
spring:
  web:
    resources:
      static-locations: classpath:/static/
  mvc:
    static-path-pattern: "/**"

You can list multiple locations, e.g., classpath:/static/,classpath:/public/ .

Check custom WebMvcConfigurer If you have a custom MVC config class, ensure it registers static resource handlers:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // static resources
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
        // WebJars
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}

Update CORS configuration Replace the deprecated method with the new pattern‑based one:

configuration.addAllowedOriginPattern("*"); // ✅ new syntax

Verify the main class annotation Make sure the entry point is annotated with @SpringBootApplication so that auto‑configuration for static resources is enabled.

@SpringBootApplication
public class YourApplication {
    public static void main(String[] args) {
        SpringApplication.run(YourApplication.class, args);
    }
}

Practical Debugging Tips

Confirm that static files are packaged: check target/classes/static/ (Maven) or build/resources/main/static/ (Gradle). Missing files indicate a packaging issue rather than a Spring config problem.

Enable debug logging for Spring’s web modules to see how resource mappings are resolved:

logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.boot.autoconfigure.web=DEBUG

After restarting, the logs will list the resolved static‑resource paths.

Other Common Upgrade Issues

JDK version: Spring Boot 3.x requires JDK 17 or higher.

Package migration: e.g., javax.validationjakarta.validation.

Swagger compatibility: Swagger 2 is no longer supported; migrate to SpringDoc OpenAPI.

Spring Security: WebSecurityConfigurerAdapter is deprecated; use a SecurityFilterChain bean.

Third‑party libraries: ensure MyBatis, Druid, Sentinel, etc., have versions compatible with Spring Boot 3.x.

Conclusion

The root cause of the “No static resource” error after a Spring Boot upgrade is the Jakarta EE package migration combined with changed static‑resource configuration. The quickest fixes are to replace javax.* imports with jakarta.*, explicitly set spring.web.resources.static-locations, and, if needed, add proper resource handlers in a custom WebMvcConfigurer. Verifying that resources are packaged and enabling debug logs further speeds up troubleshooting.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

migrationSpring BootCORSStatic Resourcesjakarta-eewebmvc
Ray's Galactic Tech
Written by

Ray's Galactic Tech

Practice together, never alone. We cover programming languages, development tools, learning methods, and pitfall notes. We simplify complex topics, guiding you from beginner to advanced. Weekly practical content—let's grow together!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.