上一篇已经搭建了eureka服务,这一次搭建config服务
创建vcloud-config
pom
4.0.0
com.pwl
vcloud
1.0.0
com.pwl
vcloud-config
0.0.1-SNAPSHOT
vcloud-config
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter
org.springframework.cloud
spring-cloud-config-server
org.springframework.boot
spring-boot-maven-plugin
application.yml
server:
port: 4001
spring:
application:
name: vcloud-config-server
---
spring:
profiles: dev
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5 #表示eureka client发送心跳给server端的频率
lease-expiration-duration-in-seconds: 20 #leaseExpirationDurationInSeconds后,server端没有收到client的心跳,则将摘除该instance
client:
serviceUrl:
defaultZone: http://root:[email protected]:1025/eureka/ #eureka 注册地址
registry-fetch-interval-seconds: 10 #表示eureka client间隔多久秒去拉取服务注册信息
启动类上添加@EnableEurekaClient注解
然后启动服务
访问eureka
注册成功
到这里config服务已经搭建好了,已经注册上了。
这里相当于注册了一个服务,但是还没有拥有拉取配置的功能,要实现拉取配置的功能请往下看
在启动类上在注解@EnableConfigServer
yml文件也要添加一些配置
spring:
application:
name: vcloud-config-server
profiles:
active: dev
cloud:
config:
server:
git:
uri: http://192.168.199.239/root/v-cloud-config.git
username: root
password: pwl123456789
其中git.uri http://192.168.199.239/root/v-cloud-config.git 这个是配置文件放在哪的路径
我这里是单独建了一个项目,并放在了gitlab上面(可以自己在本地搭建一个gitlab)
启动服务eureka和config服务
访问 http://127.0.0.1:4001/vcloud-oauth-server-dev/dev 会把配置文件从dev分支上读取出来 server.port 4000读取出来
1.在eureka页面点击服务都会跳转到登录页面上,每次启动client服务日志都会产生一个密码的问题,查找了很久,才发现问题
org.springframework.boot
spring-boot-starter-security
最根本的原因就是这个包引入的位置不对,不能引入到主POM里面,不然都会出现上面的问题,最后加到eureka项目的pom,解决问题,这就是不仔细导致的。
项目地址:https://github.com/James-Pan0525/v-cloud.git