菏泽做网站的宁乡市住房和城乡建设局网站
news/
2025/10/8 16:42:06/
文章来源:
菏泽做网站的,宁乡市住房和城乡建设局网站,空间制作网站,国家域名查询网本文通过config server连接git仓库来实现配置中心#xff0c;除了git还可以使用svn或者系统本地目录都行。引入依赖dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artif…本文通过config server连接git仓库来实现配置中心除了git还可以使用svn或者系统本地目录都行。引入依赖dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-config-server/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-eureka/artifactId/dependency
/dependenciesspring-cloud-config-server这个就是配置中心server的依赖。配置中心做到高可用本身也需要向注册中心注册自己的实例所以需求引用spring-cloud-starter-eureka依赖。添加启动类开启Config Server功能EnableDiscoveryClient
EnableConfigServer
SpringBootApplication
public class ConfigApplication {public static void main(String[] args) {SpringApplication.run(ConfigApplication.class, args);}}EnableConfigServer即开启配置服务器的功能。EnableDiscoveryClient开启自动注册客户端默认情况下ServiceRegistry实现将自动注册正在运行的服务。如注册中心使用是Eureka这里也可以使用的EnableEurekaClient注解。添加Config配置spring: application:name: config-centerprofiles:active: config-center1cloud: config:server:git:uri: ${git.uri}searchPaths: ${git.searchPaths}username: ${git.username}password: ${git.password}basedir: ${git.basedir}clone-on-start: trueforce-pull: trueeureka:instance: prefer-ip-address: true instance-id: ${spring.cloud.client.ipAddress}:${server.port}lease-expiration-duration-in-seconds: ${lease-expiration-duration-in-seconds}lease-renewal-interval-in-seconds: ${lease-renewal-interval-in-seconds}client:serviceUrl:defaultZone: ${register-center.urls}---
spring:profiles: config-center1server: port: ${config-center1.server.port}---
spring: profiles: config-center2server: port: ${config-center2.server.port}这里配置了两台Config Server都注册到了两台注册中心上。Maven filter配置#git
git.urihttp://gitlab.example.com/test/config.git
git.usernameroot
git.passwordroot
git.searchPathsconfig-center
git.basedirf:/config/config-center/gitSpring Cloud Git配置详解spring.cloud.config.server.git.urigit仓库地址。spring.cloud.config.server.git.searchPathsgit仓库搜索目录。spring.cloud.config.server.git.username连接git的用户名。spring.cloud.config.server.git.password连接git的用户名密码。spring.cloud.config.server.git.basedir配置中心在本地缓存配置的目录。spring.cloud.config.server.git.clone-on-start配置为true表示启动时就克隆配置缓存到本地。spring.cloud.config.server.git.force-pull配置为true表示如果本地副本是脏的将使Spring Cloud Config Server强制从远程存储库拉取配置。启动配置中心分别启动以下配置中心使用不同的Profile指定端口。spring-boot:run -Drun.profilesconfig-center1 -P dev
spring-boot:run -Drun.profilesconfig-center2 -P dev后续会分享更多 Spring Cloud 高级玩法栈长正在拼命撰写中……关注Java技术栈微信公众号可获取及时推送。在公众号后台回复cloud获取栈长整理的更多的 Spring Cloud 教程都是实战干货以下仅为部分预览。Spring Cloud 配置中心高可用搭建Spring Cloud 多版本如何选择Spring Cloud 是什么和 Dubbo 对比Spring Cloud 注册中心高可用搭建Spring Cloud Eureka 自我保护机制……本文原创首发于微信公众号Java技术栈id:javastack关注公众号在后台回复 cloud 可获取更多 Spring Cloud 教程转载请原样保留本信息。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/931720.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!