方法一:application.properties
在springboot的application.properties的配置文件中加入:
复制代码
1
2
3spring.resources.static-locations=file:E://uploads spring.mvc.static-path-pattern=/**
如果E://uploads下有一个1.txt文件
在地址栏中输入localhost:8080/1.txt就可以访问文件了
方法二:添加配置类
复制代码
1
2
3
4
5
6
7
8
9@Configuration public class MyWebMvcConfigurer implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("file:E://uploads/"); WebMvcConfigurer.super.addResourceHandlers(registry); } }
最后
以上就是义气楼房最近收集整理的关于springboot访问项目外部文件的全部内容,更多相关springboot访问项目外部文件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复