服务端 ConfigServer

pom.xml

		<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

spring-cloud-starter-eureka与spring-cloud-starter-eureka-server的区别

spring-cloud-starter-eureka-server已不推荐,有替代包。

原文:Spring Cloud Starter Eureka Server (deprecated, please use spring-cloud-starter-netflix-eureka-server)

见:http://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server

app类

@EnableDiscoveryClient
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

@EnableDiscoveryClient与@EnableEurekaClient的区别

Eureka推荐用后者,其他服务发现用前者。

application.yml

server:
port: ${PORT:8888} #配置工程端口号 spring:
application:
name: cloud-config-server #设置该服务应用名称
profiles:
active: native #设置读取为本地工程文件
config:
server:
native:
searchLocations: classpath:/config #配置文件根目录,也就是XXX-dev.properties等的目录 #注册到eureka服务中心进行监控
eureka:
client:
serviceUrl:
defaultZone: http://eureka:eureka@localhost:8761/eureka # 可以逗号分隔,配置多个
healthcheck:
enabled: true #开启健康监控
instance:
prefer-ip-address: true
instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}
leaseRenewalIntervalInSeconds: 30
leaseExpirationDurationInSeconds: 90

官网也用发发发发这个端口。

配置文件

config目录下配置文件:

XXX-dev.properties

XXX-test.properties

db.type=com.alibaba.druid.pool.DruidDataSource
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/MYDB?useUnicode=true&characterEncoding=UTF8
db.username=dbuser
db.password=123456

客户端AppClient

pom.xml也需要增加autuator

	<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

bootstrap.properties配置

spring.cloud.config.name=XXX
spring.cloud.config.profile=dev
#spring.cloud.config.profile=test
spring.cloud.config.uri=http\://localhost\:8888/ # 只能配置一个,不能逗号分隔配置多个config

application.yml配置

server:
port: 8080 #设置当前服务端口
context-path: /abc #设置服务上下文路径 spring:
application:
name: app-client #service name 设置当前服务名称 eureka:
client:
serviceUrl:
defaultZone: http://eureka:eureka@localhost:8761/eureka # 可以逗号分隔,配置多个
healthcheck:
enabled: true
instance:
prefer-ip-address: true # 注册到Eureka Server上的是IP
instanceId: ${spring.application.name}:${spring.application.instance_id:${server.port}}
leaseRenewalIntervalInSeconds: 15 # 心跳时间,即服务续约间隔时间(缺省为30s)
leaseExpirationDurationInSeconds: 45 # 发呆时间,即服务续约到期时间(缺省为90s)

application类

@SpringBootApplication
@EnableEurekaClient
public class ClientApplication { public static void main(String[] args) throws Exception {
SpringApplication.run(ClientApplication.class, args);
}
}

参考资料:

spring cloud config搭建说明例子(三)

spring cloud config搭建说明例子(二)

https://blog.csdn.net/hh652400660/article/details/79474419

http://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server

spring cloud config搭建说明例子(四)-补充配置文件的更多相关文章

  1. spring cloud config搭建说明例子(三)-添加actuator

    添加心跳 服务端 ConfigServer pom.xml添加actuator包 <dependency> <groupId>org.springframework.cloud ...

  2. spring cloud config搭建说明例子(二)-添加eureka

    添加注册eureka 服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</ ...

  3. spring cloud config搭建说明例子(一)-简单示例

    服务端 ConfigServer pom.xml添加config jar <dependency> <groupId>org.springframework.cloud< ...

  4. SpringCloud实战之初级入门(三)— spring cloud config搭建git配置中心

    目录 1.环境介绍 2.配置中心 2.1 创建工程 2.2 修改配置文件 2.3 在github中加入配置文件 2.3 修改启动文件 3. 访问配置中心 1.环境介绍 上一篇文章中,我们介绍了如何利用 ...

  5. Spring Cloud Config 搭建Config 服务

    配置中心: open API 配置生效监控 一致性的K-V存储 统一配置的实时推送 配置全局恢复.备份.历史版本 高可用集群 通过config 获取配置,流程: 下面介绍,基于spring cloud ...

  6. Spring Cloud Config(三):基于JDBC搭建配置中心

    1.简介 本文主要内容是基于jdbc搭建配置中心,使应用从配置中心读取配置信息并成功注册到注册中心,关于配置信息表结构仅供参考,大家可以根据具体需要进行扩展. 2.Config Server 搭建 2 ...

  7. Spring Cloud Config(二):基于Git搭建配置中心

    1.简述 本文选用Git作为配置仓库,新建两个环境的配置文件夹,dev 和 test,文件夹中分别存放 Config Client 端的配置文件,目录结构如下: ├ ─ ─ dev └ ─ ─ con ...

  8. Spring Cloud Config 分布式配置中心使用教程

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...

  9. 网络原因导致的 spring cloud config 读取git上的配置文件时报错:Cannot clone or checkout repository

    今天在公司使用spring cloud config搭建配置中心的时候,出现了读取不到git库的问题:Cannot clone or checkout repository.在网上百度,前面几个答案都 ...

随机推荐

  1. Linux笔记:定时任务和文件操作

    查看定时任务 crontab -l 注册定时任务 crontab -e然后就像 vim 一样编辑自己的定时任务.如: * * * * * . /home/hadoop/timer/check_job. ...

  2. bzoj1834 网络扩容 网络流

    好久没写题解了啊··· 题目大意: 给你一幅n个点的网络,先求出其1到n的最大流,每条弧还会有个属性\(cost_i\),表示没扩容一个单位的费用,现在我们要求的就是扩容K个单位的最小费用 思路: 这 ...

  3. python之练习-三层菜单

    今天练习编写显示3层城市名称并可以返回上一层以及退出程序. Readme: 程序概述1:程序名称为:menu_three.py2:记录省,市,县的原始文件名为:areafile3:areafile文件 ...

  4. lines-HDU5124(区间处理 +离散化)

    Problem Description John has several lines. The lines are covered on the X axis. Let A is a point wh ...

  5. linux以下安装dnw

    [root@embedded secbulk]# make -C /lib/modules/`uname -r`/build M=`pwd` modules make: *** /lib/module ...

  6. fuse-dfs挂载hdfs实录

    部署安装了最新稳定版hadoop2.2.0.然后在网上找来fuse-dfs编译教程.可是最后失败了.至今原因未知--,错误描写叙述为:Transport endpoint is not connect ...

  7. android账号与同步之账号管理

    在android提供的sdk中,samples文件夹下有一个叫SampleSyncAdapter的演示样例,它是一个账号与同步的实例,比方Google原始的android手机能够使用Google账号进 ...

  8. JS获取地址栏并拼接參数

    比方地址栏是这种:http://www.aa.com/detail.aspx?code=1&start=2014-12-01&end=2014-12-23&name=abc 要 ...

  9. android application类简单介绍(一)

    每次应用程序执行时.应用程序的application类保持实例化的状态. 通过扩展applicaiton类,能够完毕下面3项工作: 1.对android执行时广播的应用程序级事件如低低内做出响应. 2 ...

  10. HDU5294 Tricks Device(最大流+SPFA) 2015 Multi-University Training Contest 1

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...