项目需要用到微服务,需要部署,学习了一下,记录一下配置的内容:

一:

 

首先需要一个consul中继:

关于springcloud配置(配图记录)_spring

 

然后我们使用dos命令窗口打开,并且启动它:

启动命令如下

consul.exe agent -server -bootstrap -ui -client 0.0.0.0 -data-dir="D:\software\consul\data" -bind 127.0.0.1

 

 

二:

在服务端添加服务加入配置信息,我们将这个配置文件放在配置文件目录:

关于springcloud配置(配图记录)_服务端_02

以下为配置信息:

spring:
application:
name: 服务名称
cloud:
consul:
config:
#format: KEY-VALUE
format: YAML
enabled: true
prefix: configuration
defaultContext: ${spring.application.name}
#profileSeparator: '::'
watch:
enabled: true
delay: 1000
host: 127.0.0.1
#host: consul.test.svc.cluster.local
port: 8500
discovery:
enabled: true
register: true
prefer-ip-address: true
service-name: ${spring.application.name}
#hostname: 127.0.0.1
#healthCheckUrl: http://127.0.0.1:9113/actuator/health
health-check-path: /actuator/health
health-check-interval: 15s

 

 

当然还需要依赖:

关于springcloud配置(配图记录)_服务端_03

 

 

客户端配置:

关于springcloud配置(配图记录)_服务端_04

.

 

spring:
application:
name: erpnew
cloud:
consul:
config:
#format: KEY-VALUE
format: YAML
enabled: true
prefix: configuration
defaultContext: ${spring.application.name}
#profileSeparator: '::'
watch:
enabled: true
delay: 1000
host: 127.0.0.1
#host: consul.test.svc.cluster.local
port: 8500
discovery:
enabled: true
register: true
prefer-ip-address: true
service-name: ${spring.application.name}
#hostname: 127.0.0.1
#healthCheckUrl: http://127.0.0.1:9113/actuator/health
health-check-path: /actuator/health
health-check-interval: 15s

 

三:

客户端配置:启动类配置

关于springcloud配置(配图记录)_服务端_05

 

 

访问微服务内部中的接口@FeignClient(name= 微服务名称)

关于springcloud配置(配图记录)_spring_06

 

然后这样的话,我们前端请求客户端,客户端就会把相应的责任分离,去请求服务端。然后服务端返回结果给客户端,客户端出来过后给前端。