I implemented the WebMvcConfigurer interface and configured the request path, but all resources return a 404 error. When I removed the override, I could access the first-level resources under /static/js, but resources under /static/js/plugins/ are not accessible.
resource = resourceLoader.getResource("classpath:/static/");
System.out.println("Resource: " + resource.getURI());
file:/D:/code/workspace-spring-tool-suite-4-4.24.0.RELEASE/Gz-MS/target/classes/static/
thanks
Comment From: mhalbritter
If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.
https://github.com/spring-projects/spring-boot/wiki/How-To-Get-Help
Comment From: bclozel
I think addResourceLocations
is supposed to be given actual folder locations ending with "/", but the "/" should be added automatically by Spring Framework as of 6.2.0 because of https://github.com/spring-projects/spring-framework/issues/33815.
I'm moving this issue to Spring Framework and we'll wait for your minimal sample as requested by Moritz.
Comment From: iloveuaa
I think
addResourceLocations
is supposed to be given actual folder locations ending with "/", but the "/" should be added automatically by Spring Framework as of 6.2.0 because of #33815.I'm moving this issue to Spring Framework and we'll wait for your minimal sample as requested by Moritz.
i try use "/static","/static/","classpath:/static/","classpath:/static","classpath:static/" all not work, i push zip https://github.com/iloveuaa/springboot-bug/blob/main/SpringBoot.zip
Comment From: iloveuaa
If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.
https://github.com/spring-projects/spring-boot/wiki/How-To-Get-Help
i try use "/static","/static/","classpath:/static/","classpath:/static","classpath:static/" all not work, i push zip https://github.com/iloveuaa/springboot-bug/blob/main/SpringBoot.zip thanks for your time.
Comment From: bclozel
I think this is a direct consequence of:
* your application not registering a resource location as it should. Your application should have used classpath:static/
(with a trailing slash)
* the fact that #33815 did fix invalid registrations like this by appending a slash automatically
You are hitting the upgrade problem I was describing in https://github.com/spring-projects/spring-framework/issues/33815#issuecomment-2449473711. Here, "/js/**"
+ "js/main.js"
(because the resource is located in " src/main/resources/static/js/main.js"
) = "/js/js/main.js"
.
Here, you can rely on the Spring Boot auto-configuration and:
1. remove your WebConfig
class altogether as you don't need to configure this manually
2. use the spring.web.resources.static-locations=
property in application.properties
if you want to customize the locations, but I have tested without changing the default value and your sample works.
I think this is an unfortunate but expected consequence of #33815.