Spring boot 如何在springboot 2.0中加载外部覆盖属性文件?

Spring boot 如何在springboot 2.0中加载外部覆盖属性文件?,spring-boot,apache-camel,Spring Boot,Apache Camel,如何在springboot 2.0中加载外部/覆盖属性文件 注意:此问题仅针对2.0 在springboot 1.5中,我将以下内容用于覆盖属性 @Configuration @PropertySource(value = "file:/var/tmp/${spring.application.name}/${MYAPP_PROFILE:h2}/conf/override.properties", ignoreResourceNotFound = true) class AppConfig {

如何在springboot 2.0中加载外部/覆盖属性文件

注意:此问题仅针对2.0

在springboot 1.5中,我将以下内容用于覆盖属性

@Configuration
@PropertySource(value = "file:/var/tmp/${spring.application.name}/${MYAPP_PROFILE:h2}/conf/override.properties", ignoreResourceNotFound = true)
class AppConfig {
    @Bean
    public PropertyPlaceholderConfigurer placeholderConfigurer() {
        PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
        configurer.setIgnoreUnresolvablePlaceholders(true);
        return configurer;
    }
}
然而,我得到:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 43 more
编辑:

谢谢你指出。看起来@PropertySource可能不是原因。这可能是因为Apache Camel与Springboot 2.0不兼容

Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver
    at org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.isEnabled(HierarchicalPropertiesEvaluator.java:49)
    at org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.evaluate(HierarchicalPropertiesEvaluator.java:42)
    at org.apache.camel.spring.boot.util.GroupCondition.getMatchOutcome(GroupCondition.java:40)
    at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
    ... 18 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 22 common frames omitted

在我看来,当使用
Spring Boot 2.0
时,不需要
@PropertySource
注释。您可以将位置定义为如下所示:

-Dspring.config.additional-location=./conf/override.properties
有关更多参考和说明,请参阅弹簧防尘套2.0


希望这有帮助

RelaxedPropertyResolver
在Spring Boot 2.0中不存在。然而,现在还不清楚为什么这在这里很重要,因为您似乎没有使用它。你能用失败的全部痕迹更新你的问题吗?