spring cloud config搭建说明例子(四)-补充配置文件
服务端 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搭建说明例子(四)-补充配置文件的更多相关文章
- spring cloud config搭建说明例子(三)-添加actuator
添加心跳 服务端 ConfigServer pom.xml添加actuator包 <dependency> <groupId>org.springframework.cloud ...
- spring cloud config搭建说明例子(二)-添加eureka
添加注册eureka 服务端 ConfigServer pom.xml <dependency> <groupId>org.springframework.cloud</ ...
- spring cloud config搭建说明例子(一)-简单示例
服务端 ConfigServer pom.xml添加config jar <dependency> <groupId>org.springframework.cloud< ...
- SpringCloud实战之初级入门(三)— spring cloud config搭建git配置中心
目录 1.环境介绍 2.配置中心 2.1 创建工程 2.2 修改配置文件 2.3 在github中加入配置文件 2.3 修改启动文件 3. 访问配置中心 1.环境介绍 上一篇文章中,我们介绍了如何利用 ...
- Spring Cloud Config 搭建Config 服务
配置中心: open API 配置生效监控 一致性的K-V存储 统一配置的实时推送 配置全局恢复.备份.历史版本 高可用集群 通过config 获取配置,流程: 下面介绍,基于spring cloud ...
- Spring Cloud Config(三):基于JDBC搭建配置中心
1.简介 本文主要内容是基于jdbc搭建配置中心,使应用从配置中心读取配置信息并成功注册到注册中心,关于配置信息表结构仅供参考,大家可以根据具体需要进行扩展. 2.Config Server 搭建 2 ...
- Spring Cloud Config(二):基于Git搭建配置中心
1.简述 本文选用Git作为配置仓库,新建两个环境的配置文件夹,dev 和 test,文件夹中分别存放 Config Client 端的配置文件,目录结构如下: ├ ─ ─ dev └ ─ ─ con ...
- Spring Cloud Config 分布式配置中心使用教程
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...
- 网络原因导致的 spring cloud config 读取git上的配置文件时报错:Cannot clone or checkout repository
今天在公司使用spring cloud config搭建配置中心的时候,出现了读取不到git库的问题:Cannot clone or checkout repository.在网上百度,前面几个答案都 ...
随机推荐
- [NOIP2006] 提高组 洛谷P1066 2^k进制数
题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后 ...
- Ubuntu16.04安装deb文件时提示:此软件来自第三方且可能包含非自由组件
解决方式: 1.在Ubuntu软件中心安装GDebi. 2.安装好之后,选择这个要安装的deb文件右键,打开方式选择GDebi,然后输入管理员密码等待安装,期间如果不行需要重试几次. 3.另外的方法, ...
- JSP页面不支持EL表达式的解决方法
JSP页面不支持EL表达式的问题就出在新建项目时web.xml的声明上. web.xml声明部分一般分为如下版本的xsd: web-app_2_2.xsd web-app_2_3.xsd web-ap ...
- jquery校验框架
http://www.validform.club/ http://craftpip.github.io/jquery-confirm/
- maven打包插件maven-shade-plugin简单介绍
作用: 1.可以把依赖打入jar包,然后直接使用这个jar包,从而不用担心依赖问题 2.通过设置MainClass,创建一个可以执行的jar包 3.Java工程经常会遇到第三方 Jar 包冲突,使用 ...
- Django学习系列之结合ajax
AJAX简介 什么是AJAX AJAX = 异步JavaScript 和 XML(Asynchronous JavaScript and XML) 通过在后台于服务器进行少量数据交换,AJAX可以使网 ...
- CentOS 7 开启VNC Service
由於是透過 GUI 管理, 所以需要圖形桌面環境, 如果沒有安裝, 可以用以下指令安裝 GNOME: # yum groupinstall “GNOME Desktop” Centos 7安裝 VNC ...
- jQuery -> 获取指定上下文中的DOM元素
jQuery函数的第二个參数能够指定DOM元素的搜索范围. 第二个參数可分为下面类型 DOM reference jQuery wrapper document 代码演示样例 <!DOCTYPE ...
- java的输入输出流(一)
java中i/o流是java中核心的一部分,曾经学过.可是理解不够深入,渐渐的也就忘了,如今在从新学习下java的io处理,写下我学习的笔记.便于记忆,和总结归纳: 本文原创,转载请注明:http:/ ...
- 网卡bood
一.网卡bood (1)网卡bond(绑定),也称作网卡捆绑.就是将两个或者更多的物理网卡绑定成一个虚拟网卡.网卡是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在应用部署 ...