SpringCloud config 错误 springclou
2020-05-23 本文已影响0人
紫荆秋雪_文
一、 springcloud config Could not resolve placeholder 'config.info' in value "${config.info}
yml格式错误.png解决问题
我的原因是仓库yml文件格式不正确,所以不推荐直接远程仓库文件中编辑
二、config服务端配置
1、pom
<dependencies>
<!-- config 配置中心服务端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--web项目-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
2、LKTYConfigCenterApplication
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class LKTYConfigCenterApplication {
public static void main(String[] args) {
SpringApplication.run(LKTYConfigCenterApplication.class, args);
}
}
3、application.yml
server:
port: 1314
spring:
application:
name: config-center
cloud:
config:
server:
git:
# GitHub上面的git仓库名字
# uri: git@github.com:zjqx1991/springcloud-config.git
uri: https://github.com/zjqx1991/springcloud-config.git
# 搜索目录
search-paths: /
# - springcloud-config
# 读取分支
label: master
eureka:
client:
fetch-registy: true
register-with-eureka: true # 表示是否将自己注册进 EurekaServer 默认为true
fetchRegistry: true # 是否从EurekaServer 抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true 才能配合ribbon使用负载均衡
service-url:
defaultZone: http://localhost:10086/eureka
# 设置feign客户端超时时间(openFeign默认支持ribbon)
#ribbon:
# eager-load:
# enabled: true
# clients: SERVER-PAYMENT
# 指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的时间
# ReadTimeout: 5000
# 指的是建立连接后从服务器读取到可用资源所用的时间
# ConnectTimeout: 5000
feign:
hystrix:
enabled: true
# httpclient:
# # 开启 Http Client
# enabled: true
# # 最大连接数,默认:200
# max-connections: 200
# # 最大路由,默认:50
# max-connections-per-route: 50
# # 连接超时,默认2000/ms
# connection-timeout: 2000
# # 生成时间,默认:900
# time-to-live: 900
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 6000 # 设置hystrix的超时时间为6000ms
三、config-client端配置
1、pom
<dependencies>
<!-- config-client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--web项目-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
</dependencies>
2、LKTYConfigClientApplication
@EnableEurekaClient
@SpringBootApplication
public class LKTYConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(LKTYConfigClientApplication.class, args);
}
}
3、bootstrap.yml
server:
port: 1315
spring:
application:
name: config-client
cloud:
config: # Config客户端配置
label: master #分支名称
name: config #配置文件名称
profile: dev #读取后缀名称 master分支上 config-dev.yml
uri: http://localhost:1314
eureka:
client:
fetch-registy: true
register-with-eureka: true # 表示是否将自己注册进 EurekaServer 默认为true
fetchRegistry: true # 是否从EurekaServer 抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true 才能配合ribbon使用负载均衡
service-url:
defaultZone: http://localhost:10086/eureka
# 设置feign客户端超时时间(openFeign默认支持ribbon)
#ribbon:
# eager-load:
# enabled: true
# clients: SERVER-PAYMENT
# 指的是建立连接所用的时间,适用于网络状况正常的情况下,两端连接所用的时间
# ReadTimeout: 5000
# 指的是建立连接后从服务器读取到可用资源所用的时间
# ConnectTimeout: 5000
feign:
hystrix:
enabled: true
# httpclient:
# # 开启 Http Client
# enabled: true
# # 最大连接数,默认:200
# max-connections: 200
# # 最大路由,默认:50
# max-connections-per-route: 50
# # 连接超时,默认2000/ms
# connection-timeout: 2000
# # 生成时间,默认:900
# time-to-live: 900
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 6000 # 设置hystrix的超时时间为6000ms