SpringBoot外部静态资源的访问
springboot项目访问jar外部静态资源,html举例子
简单描述,在启动类中实现WebMvcConfigurer接口,实现其addResourceHandlers方法即可。
@SpringBootApplication
@EnableSwagger2
@EnableSwaggerBootstrapUI
@MapperScan("com.job.mapper")//扫描mapper包
@PropertySource(value = "classpath:config/app.properties", encoding = "UTF-8")
public class Application implements CommandLineRunner, WebMvcConfigurer {
private final Logger logger = LoggerFactory.getLogger(Application.class);
@Value("${html.agreement}")
// html.agreement=/agreement
private String agreement;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:META-INF/resources/")
.addResourceLocations("classpath:/resources/")
.addResourceLocations("classpath:/public/")
.addResourceLocations("classpath:/static/")
.addResourceLocations("file:" + agreement + File.separator);
}
@Override
public void run(String... args) throws Exception {
logger.info("Server started successfully...");
}
}
作者:cchilei
-------------------------------------------
个性签名:竹杖芒鞋轻胜马 一蓑烟雨任平生
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!