spring - Spring ConditionalOnProperty 无法读取 custom.properties 文件中的属性
问题描述
嗨,我有一些自定义属性文件,例如 application.properties。我在这些文件中放置了一些属性。我的问题是 @ConditionalOnProperty 无法读取 customproperties 文件中的 myproperties。如果我将相同的属性放在 application.properties ConditionalOnProperty 有效,但是当我将 myproperty 放在 customproperties 文件中时它不起作用。除了 ConditionalOnProperty 我从自定义属性文件中读取值没有任何问题。有没有办法从Spring Boot 中的 ConditionalOnProperty。
@Congiuration
@PropertySource("classpath:myproperties.properties")
@ConfigurationProperties(prefix="mycustomprop")
public class MyProperties{
private String myproperty;
@Configuration
@ConditionalOnProperty(name = "mycustomprop.myproperty", havingValue = "false") //not work when myproperty in customproperty file
public class MyConfiguration implements WebMvcConfigurer
@SpringBootApplication
@PropertySources({
@PropertySource("classpath:myproperties.properties")
})
public class MyApplication
解决方案
您@PropertySource annotation
需要继续@Configuration
上课(或@SpringBootApplication,如果您愿意),而不是您的自定义 MyProperties 对象。
推荐阅读
- roku - 改变brightscript的roAssociativeArray中某个字段的值
- php - 没有密钥的 Laravel 雄辩关系
- javascript - 隐藏输入在 Javascript 中设置提交之前具有值;一旦提交它在后端为空
- r - 从向量访问数据
- gcc - 在 Mac OS 上使用 Homebrew 安装 gcc 时缺少 ld 链接器
- android - 无法将 Main Activity 中的 Fragment 加载到框架布局中
- excel - 在 VBA for Excel 中粘贴对象的 xlPlacement 枚举?
- r - 根据 R 中的其他两列计算列中的值
- ruby-on-rails - 自定义字体(通过资产管道)没有出现在带有 Rails 5.2 的 Heroku 上
- webpack - 使用 create-react-app-typescript 和电子时设置 nodeIntegration: false