gpt4 book ai didi

java - 不工作 spring.config.additional-location

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:19:52 25 4
gpt4 key购买 nike

maven :

<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<active.spring.profile>local</active.spring.profile>
</properties>
</profile>
</profiles>

应用程序属性:

spring.profiles.active=@active.spring.profile@
spring.config.additional-location=classpath:/profile/application-${spring.profiles.active}.properties

在此之后我无法从包含 test.prop=123

的 src/main/resources/application-local.properties 获取值
@Service
public class TestProps {

@Value("${test.prop}")
String testProp;

@PostConstruct
void run() {
System.out.println(testProp);
}
}

错在哪里?还是错误?

最佳答案

属性:spring.config.additional-location 必须像这样作为 JVM 的参数提供:java -Dspring.config.additional-location=classpath:/profile/application -local.properties -jar whatever.jar.

将它放在 application.properties 中没有意义。来自documentation :

Alternatively, when custom config locations are configured by usingspring.config.additional-location, they are used in addition to thedefault locations. Additional locations are searched before thedefault locations.

因为附加位置是在默认位置之前搜索的,所以它们必须更早提供,因此您不能在application.properties

关于java - 不工作 spring.config.additional-location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53729748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com