【发布时间】:2017-08-31 12:06:21
【问题描述】:
情况
我将 .properties 文件中的属性注入到带有 @Value 注释的字段中。但是,此属性提供敏感凭据,因此我将它们从存储库中删除。如果有人想要运行项目并且没有带有默认值将设置为字段的凭据的 .properties 文件,我仍然希望这样做。
问题
即使我将默认值设置为字段本身,当 .properties 文件不存在时也会出现异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxx': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'secret' in string value "${secret}"
这里是带注释的字段:
@Value("${secret}")
private String ldapSecret = "secret";
我预计在这种情况下只会设置普通字符串“secret”。
【问题讨论】:
标签: java spring spring-boot spring-annotations properties-file