博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(十五)spring cloud微服务分布式云架构-commonservice-config配置服务搭建
阅读量:6857 次
发布时间:2019-06-26

本文共 4268 字,大约阅读时间需要 14 分钟。

  1. 介绍

Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。很容易添加替代实现,并使用Spring配置将其插入。Spring Cloud大型企业分布式微服务云架构源码请加一七九一七四三三八零

  1. 引入pom相关jar包,其中pom.xml配置如下:
4.0.0
com.ml.honghu
commonservice
0.0.1-SNAPSHOT
commonservice-config
jar
commonservice-config
Config Server
org.springframework.cloud
spring-cloud-config-server
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.boot
spring-boot-starter-security
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
1
repackage
2
build-info
复制代码
  1. 在src/main/java进行ConfigApplication.java启动文件配置:
package com.ml.honghu;    import org.springframework.boot.SpringApplication;  import org.springframework.boot.autoconfigure.SpringBootApplication;  import org.springframework.cloud.config.server.EnableConfigServer;  import org.springframework.cloud.netflix.eureka.EnableEurekaClient;    @EnableConfigServer  @EnableEurekaClient  @SpringBootApplication  public class ConfigApplication {        public static void main(String[] args) {          SpringApplication.run(ConfigApplication.class, args);      }  }  复制代码
  1. 在src/main/resource下进行bootstrap.yml配置
server:   port: 8888  spring:    application:      name: commonservice-config-server    profiles:      active: discovery,native    cloud:      config:        server:          git:            uri: http://192.168.0.254/honghu.../honghu-config.git            username: honghu            password: 123456            searchPaths: config-dev  security:    basic:      enabled: true    user:      name: honghu      password: 123456  eureka:    client:      serviceUrl:        defaultZone: http://honghu:123456@localhost:8761/eureka/        honghuZone: http://honghu:123456@localhost:8761/eureka/      registry-fetch-interval-seconds: 300      availability-zones:        honghu: honghuZone    instance:      prefer-ip-address: true      metadataMap:        version: 1.0        variant: A        user: ${security.user.name}        password: ${security.user.password}  management:    security:      enabled: false  复制代码

注意: 如果不从远程git或者svn库加载配置文件信息,可以配置加载本地地址,比如window下配置使用:

server:   port: 8888  spring:    application:      name: commonservice-config-server    profiles:      active: discovery,native    cloud:      config:        server:          native.searchLocations: d:/honghu-config  security:    basic:      enabled: true    user:      name: honghu      password: 123456  eureka:    client:      serviceUrl:        defaultZone: http://honghu:123456@localhost:8761/eureka/        honghuZone: http://honghu:123456@localhost:8761/eureka/      registry-fetch-interval-seconds: 300      availability-zones:        honghu: honghuZone    instance:      prefer-ip-address: true      metadataMap:        version: 1.0        variant: A        user: ${security.user.name}        password: ${security.user.password}  management:    security:      enabled: false  复制代码

到此,整个config服务项目配置完毕!

转载于:https://juejin.im/post/5c8868f05188257e1b351fb4

你可能感兴趣的文章
chocolatey使用
查看>>
【转】iOS高级向的十道面试问题
查看>>
昂贵的聘礼 poj 1062 Dijkstra
查看>>
Hadoop HA的搭建
查看>>
JavaScript实现搜索框效果
查看>>
搭建nginx流媒体服务器(支持HLS)
查看>>
struts2上传文件大小受限问题
查看>>
dao使用JdbcTemplate(注入过程)视频学习
查看>>
无刷新URL 更新
查看>>
狮入羊口
查看>>
HDU 1421 搬寝室[DP]
查看>>
二层设备与三层设备的区别--总结
查看>>
ZOJ 3829 Known Notation(字符串处理 数学 牡丹江现场赛)
查看>>
JS操作css样式用法
查看>>
怎样使用 CCache 进行 cocos2d-x 编译加速
查看>>
Thymeleaf 3.0 专题
查看>>
Spring下的@Inject、@Autowired、@Resource注解区别(转)
查看>>
View的setTag()与getTag()方法使用
查看>>
UML中类结构图示例
查看>>
03-hibernate注解-关系映射级别注解-一对一
查看>>