一.首先本地启动一个eureka服务
http://localhost:8763/eureka/
使用浏览器访问的话不能加/eureka这个后缀。使用下面的地址:
http://localhost:8763/
二.配置server服务端
说明一下:我是使用公司的已经写好的配置,就是开始的时候不懂各个配置的含义,导致在写client端出现各种问题,特发表文章记录一下。
直接上代码:
pom.xml
其中eureka包是spring版本问题,所以引用方式不一样
actuator这个包是用来实时更新配置的
启动类添加注解
@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
application-dev.yml
server:
port: 8888
eureka:
instance:
hostname: spring-cloud-config
prefer-ip-address: true
client:
registerWithEureka: true
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:8763/eureka/
spring:
application:
name: spring-cloud-config
profiles:
active: git #设置使用本地配置(默认是git,可以设置:subversion(SVN),native(本地))
cloud:
client:
hostname: spring-cloud-config
config:
label: master
monitor:
endpoint:
path: /config
server:
prefix: /config #这里配置了前缀,那么你访问的时候就要加上这个前缀
encrypt:
enabled: true #这里询问是否要加密,注意:要为true,为false的话client端无法连接成功,具体原因还待后续研究
monitor:
github:
enabled: true
git:
uri: http://10.72.76.54/liu/my-gitlab-test.git # 配置git仓库的地址(最后不需要带/,否则会出现:No custom http config found for URL: XXX)
cloneOnStart: true
username:
search-paths: config
password:
basedir: target/configs
accessToken: # git仓库的密码(公开仓库无需账号信息)
encrypt:
key: tenxcloud-configserver-encrypt-key
management:
endpoints:
web:
exposure:
include: env,bus-refresh
base-path: /
eureka显示页面
可以看到已经注册成功了
三.config client端
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5