spring.config.location 在 Spring Boot 2.0.0 M6 上不起作用

标签 spring spring-boot kotlin

我正在将我的一项微服务迁移到 Spring Boot 2.0.0.M6,但在命令行上使用 --spring.config.location= 选项时出现错误。错误如下:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'property' in value "${property}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:834) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1081) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:578) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:367) ~[spring-beans-5.0.1.RELEASE.jar:5.0.1.RELEASE]
... 50 common frames omitted

如果我不使用自定义属性文件,一切都会按预期工作,或者使用 RELEASE 版本。我正在使用以下命令启动应用程序:

java -jar application.jar --spring.config.location=app.properties

更新

我注意到,当使用此选项时,Spring 完全替换了项目中的默认 application.properties,这与之前的 Spring 版本不同,它只是覆盖了参数文件中的属性。这是一个错误吗?

更新 2

得到了 response从团队来看,显然这是有意的行为。现在想知道是否有办法使用旧版本的行为。

最佳答案

正如 Spring 团队所说,使用 spring.config.location 中旧行为的正确方法是使用新的 spring.config.additional-location

关于spring.config.location 在 Spring Boot 2.0.0 M6 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47209348/

相关文章:

java - 当从@transactional公共(public)方法调用私有(private)方法时,私有(private)方法中会使用相同的事务还是不使用事务

java - 预定作业中的 Spring 应用程序 URL

spring-boot - 带有 URL 的 Spring Boot YAML 配置在版本 2 中不再正确加载

null - Kotlin设置为Null(如果不为Null)

android - Dagger 无法提供 Kotlin 注入(inject)

spring - 由于缺少ServletWebServerFactory bean,因此无法启动ServletWebServerApplicationContext。错误仍然存​​在

java.lang.illegalargumentException 无法将 java.lang.string 字段设置为 java.lang.String

spring-boot - Spring Boot 2 和 OAuth2/JWT

java - 在 Spring Boot 中将 @Bean 放在哪里?

Android Studio 在有效的 Kotlin 代码中显示错误