spring boot訪問靜態資源出錯
阿新 • • 發佈:2018-12-27
1.寫一個配置類
import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * 解決 templates 下訪問不了靜態資源問題 * @Authof: ZhangYingHao * @Date: Create in 15:40 2018/7/27 */ @Configuration public class MyConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } }
2.直接在application.properties檔案中修改
spring.mvc.static-path-pattern=/static/**