在我的项目中,我具有该启动程序的启动程序和spring-boot应用程序。
入门包含几乎没有属性的application.yaml文件。 例如:
my:
test:
value: test
spring:
profiles:
active: development
我正在将application.yaml文件添加到我的spring-boot应用程序中,并且启动器的yaml中的值不会注入到上下文中。 我的问题, 我如何在启动器和应用程序中配置2个Yaml文件以及如何使用spring-boot应用程序的启动器覆盖值的选项,例如:
spring:
profiles:
active: testing
合并后,我希望拥有:
spring.profiles.active =测试
my.test.value = test
当前它因错误而失败: 原因:java.lang.IllegalArgumentException:无法解析值“ $ {my.test.value}”中的占位符“ my.test.value”
答案 0 :(得分:2)
使用spring:
profiles:
active: testing
include: default
application-profile.yml
或者您可以创建其他java -jar name.jar spring.profiles.active=testing // it will pick the properties values from application-testing.yml
(例如application-testing.yml)并在启动Spring Boot应用程序时指定配置文件
命令
spring:
profiles:
include: default
在yml文件中,使用include包括其他任何配置文件
application-testing.yml
export class ProfileFollowService {
//global variable which should be updated
followState: boolean;
constructor(private angularFirestore: AngularFirestore) { }
checksFollow(followingID: string, followerID: string): boolean {
const followDoc =
this.angularFirestore.collection(`users/${followingID}/following`).doc(followerID).ref;
followDoc.get().then((doc) => {
if (doc.exists) {
this.followState = true;
} else {
this.followState = false;
}
});
return this.followState;
}
}
答案 1 :(得分:0)
@死侍 覆盖问题 我在启动程序中创建了application-starter.yaml,并使用include将其包含在sprinng-boot中。
my:
test:
value: spring--123
spring:
profiles:
active: development
include: starter
我注入了@Value
@Value("${my.test.value}")
private String testval;
和testval = test(从入门版开始)是否有i选项可以使application.yaml的值更主要?
谢谢