博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(九)Java springcloud B2B2C o2o多用户商城 springcloud架构 - commonservice-config配置服务搭建...
阅读量:7014 次
发布时间:2019-06-28

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

1. 介绍

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

2. 引入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
复制代码

3. 在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);      }  }  复制代码

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

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。

Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求: 一零叁八七七四六贰六 

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

你可能感兴趣的文章
A380上11万一张的机票什么享受?来看看
查看>>
LeetCode: 103_Binary Tree Zigzag Level Order Traversal | 二叉树Zigzag层次遍历 | Medium
查看>>
JUnit单元测试中的setUpBeforeClass()、tearDownAfterClass()、setUp()、tearDown()方法小结
查看>>
Java程序猿JavaScript学习笔记(2——复制和继承财产)
查看>>
ubuntu15.10下编译安装wine1.8 rc4
查看>>
Hello,HTML 到 HTML5
查看>>
jquery获取节点的时候获取包含自己在内的HTML标签
查看>>
android之AlertDialog 点击其它区域自己主动消失
查看>>
小程序 - 提示框
查看>>
Windows 10下安装配置Caffe并支持GPU加速(修改版)
查看>>
CPU profiling
查看>>
feign调用接口session丢失解决方案
查看>>
利用 SPL 快速实现 Observer 设计模式
查看>>
本体感受和演讲能力
查看>>
Spring MVC+Ant+Tomcat+Eclipse最简单的demo
查看>>
JavaScript 对象
查看>>
UrlDecode
查看>>
Quartz.Net在windows服务中的使用
查看>>
一条直线上N个线段所覆盖的总长度
查看>>
sql server 2008学习13 触发器
查看>>