java - Spring Boot - 不要解析 application.properties 文件中的占位符
问题描述
我正在使用带有 Camel 框架的 Spring Boot。
我需要保存一个属性,例如:
output.file=file://C:/Users/bfrisco/Desktop/output?fileName=${headers.fileName}
我需要这个原始字符串。我不希望 Spring 尝试解决${headers.fileName}
,我想要我输入的文本。启动我的应用程序时,我将收到此错误:
无法解析占位符“headers.fileName”
该值是动态的,并且会在运行时发生变化。Camel 将以不同于 Spring 的方式解释这个属性。我一直无法找到一种方法来阻止 spring 在启动时尝试解释这一点。
我有这个可行的解决方法,但它并不理想,我觉得有更好的方法:
# Inserted a ! between so Spring does not interpret it
output.file=file://C:/Users/bfrisco/Desktop/output?fileName=$!{headers.fileName}
@Value("${output.file}")
private String outputFile;
@PostConstruct
public void init() {
outputFile = outputFile.replaceAll("!", "");
}
有没有办法解决这个问题,而无需在每个需要使用这些值的类中实现此解决方法?
解决方案
你可以用
output.file=file://C:/Users/bfrisco/Desktop/output?fileName=#{'$'}{headers.fileName}
推荐阅读
- reactjs - 我怎样才能在反应中为formData创建if else?
- razor - 剃须刀页面中的模型绑定不绑定对象
- javascript - Redux store reducer 实现了错误的接口
- android - 为什么在 Google Play 封闭式测试中使用我的应用时出现奇怪的 Gmail 帐户
- google-search - 我的空格键删除了 Google 搜索或 youtube 上的文字
- django - 如何在 django 中使用一个查询在没有 FK 的情况下检索相关实例
- python - 按名称将网络抓取结果保存到 txt 文件
- php - 亚马逊广告卷曲 PHP
- javascript - 如何修复错误:Fontconfig 错误:无法加载默认配置文件
- shell - 插入符号和 ANSI 转义序列之间的区别