首页 > 解决方案 > @Value 在第三方 jar spring boot 中的类文件中

问题描述

我正在将一个旧的基于 Spring XML 配置的应用程序迁移到 Spring Boot,并且有第三方 jars@Value("$在其中引用了属性。我尝试加载放置/resources在新 Spring Boot 工作区中的自定义属性文件并加载它,@PropertySource("classpath:file")但在 Spring Boot 运行期间,该属性似乎没有被加载并得到以下错误:

     Could not resolve placeholder 'com.example.propertyName' in value "${com.example.propertyName}"
     at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) 
     ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]

标签: javaspringspring-boot

解决方案


您可以使用注释 @Value 绑定属性值,然后在其上提及键。

您可以按照以下链接查看端到端示例

点击


推荐阅读