添加心跳

服务端 ConfigServer

pom.xml添加actuator包

		<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的区别?

app不变

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

@EnableDiscoveryClient与@EnableEurekaClient的区别?

application.yml添加healthcheck

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

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

配置文件

新建配置文件:

XXX-dev.properties

XXX-test.properties

客户端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配置,和config一样增加health

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搭建说明例子(三)-添加actuator的更多相关文章

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

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

  2. spring cloud config搭建说明例子(四)-补充配置文件

    服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</groupId> ...

  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 读取git上的配置文件时报错:Cannot clone or checkout repository

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

  7. spring cloud config配置

    参考: http://www.ityouknow.com/springcloud/2017/05/22/springcloud-config-git.html http://www.ityouknow ...

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

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

  9. 搭建spring cloud config

    很久没更新了,因为不是专职研究spring cloud,因此更新速度得看工作强度大不大,每天能抽出的时间不多,如果更新太慢了,并且有小伙伴看的话,请见谅了. Spring Cloud简介 Spring ...

随机推荐

  1. POJ 1988相对偏移

    //不容易啊,终于自己a了一道这种类型的题 // #include<stdio.h> #include<iostream> using namespace std; const ...

  2. Linux下汇编语言学习笔记56 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  3. java中文乱码问题的处理方式

    URL访问java时. 注意: URL: 编码二次 URLEncoder.encode(URLEncoder.encode(searchKey, "utf-8"),"ut ...

  4. Java中如何获取spring中配置的properties文件内容

    有2种方式: 一. 1.通过spring配置properties文件 [java]  <bean id="propertyConfigurer"      class=&qu ...

  5. 子元素设置margin-top,父元素也受影响

    这个问题困惑了非常久.尽管没有大碍早就摸出来怎么搞定它.但始终不明确原因出在哪里,假设仅仅是IE有问题我也不会太在意.可问题是全部上等浏览器都表现如此,这样叫我怎能安心?今天总算下狠心查出来怎么回事, ...

  6. [TypeScript] Define Custom Type Guard Functions in TypeScript

    One aspect of control flow based type analysis is that the TypeScript compiler narrows the type of a ...

  7. apache ab 測试 apr_socket_connect(): 因为目标机器积极拒绝 无法连接

    遇到这样的情况通常是你开的并行数量太多了... 比如:ab -c 1000 -n 10000 http://localhost/index.html 如此大的请求就会挂掉,只是还是有补救措施的,能够通 ...

  8. js中的封装、继承、多态

    Javascript是一门解释型的语言,是基于对象的,并不是真正的面向对象的语言,对变量类型的应用也是宽松的,其实它同样可以模拟面向对象的功能:  1 function myfun1(){  2    ...

  9. Mysql-SQL优化-统计某种类型的个数

    有时我们想统计某种类型有多少个,会用这个SQL. 全表扫描之余,还要filesort.耗时1.34秒. mysql> select country,count(*) from t1 group ...

  10. [swift实战入门]手把手教你编写2048(一)

    苹果设备越来越普及,拿着个手机就想捣鼓点啥,于是乎就有了这个系列,会一步一步教大家学习swift编程,学会自己做一个自己的app,github地址:https://github.com/scarlet ...