我有一个 Spring Boot 应用程序,我想按特定顺序将值注入到 @ConfigurationProperties bean 中。
例如,
@ConfigurationProperties("myproperties")
class MyProperties {
private String property1;
....
}
基础应用程序.yml
myproperties:
property1: some-value
上面的类和属性文件位于 jar 文件中。在我的 Spring Boot 应用程序(具有上述 jar 作为依赖项)的邮件应用程序中,我使用了@PropertySource(value = { "application.yml", "base-application.yml"})
但得到了null
值在MyProperties
.
I tried
@PropertySources({
@PropertySource("classpath:application.yml"),
@PropertySource("classpath*:base-application.yml")
})
也是如此,但这也不起作用。
如果我在 application.yml 中添加 myproperties.property1 值,那么它可以正常工作。是否可以从另一个 jar 内的属性文件注入属性值?如果是这样,我在这里做错了什么?
YAML files can’t be loaded via the @PropertySource annotation. So in
the case that you need to load values that way, you need to use a
properties file.
Check the docs here https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-yaml-shortcomings
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)