springcloud~配置中心实例搭建
server端
build.gradle相关
dependencies {
compile('org.springframework.cloud:spring-cloud-config-server',
'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
)
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
bootstrap.yml配置
server:
port: 8200
spring:
application:
name: lind-config-server
cloud:
config:
server:
git:
uri: https://github.com/bfyxzls/lindconfig.repo.git/
search-paths: config-repo
username: bfyxzls@sina.com
password: xxxx
启动项相关
@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
class Application {
public static void main(String[] args) {
// demo http://localhost://8200/email-svt.yml
SpringApplication.run(Application.class, args);
}
}
客户端
build.gradle相关
dependencies {
compile('org.springframework.boot:spring-boot-starter-web',
'org.springframework.cloud:spring-cloud-starter-config',
'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
bootstrap.yml配置
spring:
application:
name: lind
cloud:
config:
uri: http://localhost:8200
profile: svt
label: master #当 ConfigServer 的后端存储的是 Git 的时候,默认就是 master
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
启动项相关
@EnableEurekaClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@RestController
public class HomeController {
@Autowired
private Environment profile;
@RequestMapping("/")
public String index(@RequestParam String key) {
return key + "=" + profile.getProperty(key);
}
}
配置文件仓库
这是一个GIT仓库,主要存储我们的配置文件的,以application.name作为文件名,profile作为后缀,我们客户端就是某个应用程序,它以后从仓库获取配置信息。
程序配置例子
lind.yml
默认的配置
lind.svt.yml
测试环境配置,将集成默认配置
lind.production.yml
生成环境配置,将集成默认配置
配置中心例子
合集:
springcloud
分类:
Java
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
2017-06-20 docker~Dockerfile优化程序的部署
2016-06-20 插件~使用ECharts动态在地图上标识点
2013-06-20 EF架构~引入规约(Specification)模式,让程序扩展性更强
2012-06-20 面向对象的故事~数据底层操作告诉了我们接口,抽象类,继承与多态性的使用