java - SpringBoot 从自定义路径提供静态图像
问题描述
现在我一直通过application.properties
文件中的静态路径提供我的图像:
spring.resources.staticlocations=file:/Applications/MAMP/htdocs/reportMaker/template
spring.mvc.static-path-pattern=/resources/**
然后通过做
http://localhost:8080/resources/logo.png
我能够到达徽标。
现在我的目标是使用从我的数据库中获取的文件夹路径进行切换。
我试过这种方法:
@EnableWebMvc
@Configuration
public class StaticResourceConfiguration implements WebMvcConfigurer {
@Autowired
ConfigurationRepository confRepo;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
myConfiguration conf = confRepo.findByConfKey("downloadPath");
String path = conf.getConfValue();
if(path !=null) {
registry.addResourceHandler("/resources/**").addResourceLocations(path);
}
}
但是我无法以与以前相同的方式到达徽标。
路径变量是/Applications/MAMP/htdocs/reportMaker/template
。
解决方案
路径变量是
/Applications/MAMP/htdocs/reportMaker/template
。
根据此文档https://www.baeldung.com/spring-mvc-static-resources路径应以file:/
推荐阅读
- ios - 多行截断中间不能快速工作
- sql - 两个事务之间的写冲突
- ios - 将 VStack 的位置保存在 @State 私有变量中
- sql - 如何在 Oracle DB 中使用 max(Date) 和 Distinct。我想在一天内最后插入数据
- oracle - 插入内部触发器不触发
- javascript - 使用 moment js 将分钟转换为天、小时和分钟
- html - 向右移动 gif 图像
- reactjs - 出现错误:反应中未定义函数
- php - Illuminate\Database\QueryException SQLSTATE[23000]:完整性约束违规:1048 列“f_name”不能为空
- python - 无法更新谷歌电子表格 api 中的对齐方式,未知名称“字段”,python,如何修复?