Spring boot 使用HashiCorp Consor和Spring Boot的分布式配置
我想知道如何使用SpringBoot在HashiCorp-Concur中共享一些属性,我读到有依赖项“SpringCloud-Concur-config”,但我找不到如何从那里加载包含所有属性文件的文件夹 使用Spring云配置服务器,这是可能的,例如:Spring boot 使用HashiCorp Consor和Spring Boot的分布式配置,spring-boot,consul,spring-cloud-config,Spring Boot,Consul,Spring Cloud Config,我想知道如何使用SpringBoot在HashiCorp-Concur中共享一些属性,我读到有依赖项“SpringCloud-Concur-config”,但我找不到如何从那里加载包含所有属性文件的文件夹 使用Spring云配置服务器,这是可能的,例如: spring: profiles: active: native cloud: config: server: native: searchLocations: fi
spring:
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: file:C:/springbootapp/properties/
但是,如何在Spring Cloud Config Concur中实现这一点?假设您在标准端口上运行Concur,那么使用Spring boot不需要太多配置。整个代码粘贴在下面(没有其他配置文件) 对我来说,棘手的部分是弄清楚如何将键/值存储在concur中,以便SpringBoot应用程序可以看到。文档中有一些信息,但我认为有点误导 为了回答您的问题,我将值放在consur内的“config/bootstrap/key1”键下,以使下面的示例正常工作 下面是一个适用于我的示例代码: pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
<version>1.0.0.M5</version>
</dependency>
您好,Mateusz,如果属性设置为path/config/application/data,我可以从Consor读取属性,我的目标是从本地文件夹将所有属性文件发布到Consor服务器,例如Spring config server使用本机配置文件。有什么办法吗?我不知道我是否理解:您想在启动期间将文件中的所有属性发布到Consor服务器?如果是的话,我不认为这是图书馆的目标。如果无法使用该库,我认为使用Concur客户端库编写代码应该相当容易。是的,就是这样。。使用SpringCloudConfigServer,这是可能的。。。因此,我可以在客户端应用程序中共享我的所有属性值。Spring Cloud Config Server和Spring Cloud Consor Config的用途略有不同。第一个应用程序确实用于向其他应用程序提供配置(如果您没有第三方配置服务器,则您的应用程序将成为配置服务器),而第二个应用程序则为您提供连接到Consor(第三方配置服务器)的方法。这样做的目的是,您的环境中已经提供了concur,并且配置已经就绪。可以在开发环境中使用一个实例,在生产环境中使用另一个实例,并使用不同的值集。
@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class Application {
@Autowired
private Environment env;
@RequestMapping("/")
public String home() {
return env.getProperty("key1");
}
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}