栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

整合spring cloud云服务架构

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

整合spring cloud云服务架构

(九)整合spring cloud云服务架构 - commonservice-config配置服务搭建

1. 介绍

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

2. 引入pom相关jar包,其中pom.xml配置如下:

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  
                                              
                                      
                  
              
          
      

 3. 在src/main/java进行ConfigApplication.java启动文件配置:Java代码

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下配置使用:Java代码

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服务项目配置完毕!!

 

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,有spring cloud b2b2c电子商务需求的朋友可以加企鹅求求:三五三六二四七二五九,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。

 


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/234903.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号