Spring Cloud配置服务器是基于Rest的应用程序,建立在Spring Boot上。Spring Cloud配置服务器不是独立服务器,相反,可以选择将它嵌入现有的Springboot应用程序中,也可以在嵌入他的服务器中启动新的Springboot项目。
构建简单的许可证服务框架,返回一个代表数据库中单个许可记录的硬编码Java对象。
一、maven配置
二、Springcloud Config引导类
1 @SpringBootApplication 2 @EnableConfigServer 3 public class ConfigServerApplication { 4 public static void main(String[] args) { 5 SpringApplication.run(ConfigServerApplication.class, args); 6 } 7 }
@EnableConfigServer使服务成为SpringCloudConfig服务
三、使用带有文件系统的SpringCloud配置服务器
1 spring: 2 profiles: 3 active: native 4 cloud: 5 config: 6 server: 7 native: 8 searchLocations: classpath:config/,classpath:config/licensingservice
searchLocations属性为每一个应用程序提供了逗号分隔的文件夹列表,这些文件夹含有由配置服务器管理的属性。
四、访问开发环境时,会返回两组配置信息,原因是:Spring框架实现了一种用于解析属性的层次结构机制,当Spring框架执行属性解析时,它将始终先查找默认属性中的属性,然后用特定环境的值(如果存在)去覆盖默认属性,如果其他环境不存在默认属性,将使用这个默认值。
原文:https://www.cnblogs.com/cloudgank/p/11331439.html