第一步 配置前置的访问入口
application.yml
第二部 加载资源路径配置
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* @liutuo springboot 配置适配器,加载拦截器过滤器等spring的bean
*/
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Value("${spring.web.resources.static-locations:classpath:/static/}")
private String locationPath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations(locationPath);
}
}
我的前台的资源都是static为路径的所以截取配置了
registry.addResourceHandler("/static/**")
然后再把application.yml的配置加入进来即可完成