When I first started learning springboot, I was unable to access the static resources when calling the static resources. The reason was that the static files were in the wrong directory. They were not created under main/resources, but were created directly in the project root directory.
package org.myboot.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration public class WebAppConfigurer extends WebMvcConfigurerAdapter{ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/myfile/**").addResourceLocations("classpath:/myfile/"); super.addResourceHandlers(registry); } }
Correct directory :
Error directory: