问题描述
我要将自己的微服务之一迁移到Spring Boot 2.0.0.M6,在命令行上使用--spring.config.location=
选项时出现错误.错误如下:
I'm migrating one of my micro-services to Spring Boot 2.0.0.M6 and I got and error while using the --spring.config.location=
option on the command line. The error is the following:
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版本.我使用以下命令启动应用程序:
If I don't use the custom property file everything works as intended or use the RELEASE versions. I'm starting the application with the following command:
java -jar application.jar --spring.config.location=app.properties
我注意到,使用此选项时,Spring会完全替换项目中的默认application.properties,这与以前的Spring版本不同,后者仅会覆盖参数文件中的属性.这是一个错误吗?
I notice that when using this option Spring completely replaces the default application.properties from the project, unlike previous Spring versions which just overwrites the properties in the argument file. Is this a bug?
得到了团队的响应,显然这是预期的行为.现在尝试了解是否有一种方法可以使用旧版本的行为.
Got a response from the team, apparently this is intended behavior. Trying to know now if there is a way to use the old versions behavior.
推荐答案
如Spring团队所述,使用spring.config.location
中的旧行为的正确方法是使用新的spring.config.additional-location
As stated by the Spring team the correct way to use the old behavior from the spring.config.location
is to use the new spring.config.additional-location
这篇关于spring.config.location在Spring Boot 2.0.0 M6上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!