SpringBoot2.x過後static下的靜態資源無法訪問
阿新 • • 發佈:2018-12-19
package com.example.thymeleaf.commons; import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * 配置靜態資源對映 * * @author sunziwen * @version 1.0 * @date 2018-11-16 14:57 **/ @Component public class WebMvcConfig implements WebMvcConfigurer { /** * 新增靜態資原始檔,外部可以直接訪問地址 * * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } }