gpt4 book ai didi

java - Spring Boot 自定义属性

转载 作者:行者123 更新时间:2023-12-01 13:37:09 26 4
gpt4 key购买 nike

在我的项目中有 2 个资源属性
1. application.properties

server.port=8002

spring.data.mongodb.host=
spring.data.mongodb.port=
spring.data.mongodb.database=
spring.data.mongodb.username=
spring.data.mongodb.password=
2. application-development.properties
server.port=8002

spring.data.mongodb.host=
spring.data.mongodb.port=
spring.data.mongodb.database=
spring.data.mongodb.username=
spring.data.mongodb.password=

spring.data.solr.host
这个类使用了 development 的 value 属性
@Configuration
@EnableSolrRepositories(basePackages = {
"id.alfadigital.alfagift.service.product.v1.db.solr.repository",
"id.alfadigital.alfagift.service.product.v2.db.solr.repository"
})
public class SolrConfiguration {

@Value("${spring.data.solr.host}")
private String solrUrl;

@Bean
public SolrClient solrClient() {
return new HttpSolrClient.Builder(solrUrl).build();
}

@Bean
public SolrTemplate solrTemplate(SolrClient client) {
return new SolrTemplate(client);
}
}

I use application-development.properties as my project resoure


所以我使用以下命令运行项目: mvn spring-boot:run -D spring.profiles.active=development但是当我运行项目时附加了一个错误
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solrConfiguration': 
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException:
Could not resolve placeholder 'spring.data.solr.host' in value "${spring.data.solr.host}"
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.data.solr.host' in value "${spring.data.solr.host}"
我很困惑,我的错误在哪里,我该怎么办?

最佳答案

您能否使用以下命令运行您的应用程序。由于错误使用命令它无法拿起development轮廓。mvn spring-boot:run -Dspring.profiles.active=development例子:
how to use Spring Boot profiles

关于java - Spring Boot 自定义属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62748029/

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