今天有人问我这个,初次使用 spring cloud 配置管理后,一运行 编译报错
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'hello' in value "${hello}"
百度一下解决问题,感觉网上说的不是很清楚,新手的话一时半会可能看不懂,自己就写一篇博客吧。力求人人都能看懂。
解决方法
配置文件 用 bootstrap.properties
配置如下
# 和git里的文件名对应
spring.application.name=client
# 远程仓库的分支
spring.cloud.config.label=master
# dev 开发环境配置文件 | test 测试环境 | pro 正式环境
# 和git里的文件名对应
spring.cloud.config.profile=dev
# 注册在总服务里面的,配置服务 地址
spring.cloud.config.uri= http://localhost:8888/
server.port=7020
下面是选看的内容
先看一下我的工程配置,大家也可以对照一下,是否你们的错误了
spring cloud server
这个呢,就是spring cloud的总服务,所有的其他分布式工程都会注册到这里。
application.yml
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
#总服务的打开地址
defaultZone: http://${
eureka.instance.hostname}:${
server.port}/eureka/
Note:运行这个项目后,我们打开上面我们自己定义的网址 defaultZone
当其他分布式项目没有运行时候,如图所示。
如果,其他分布式项目运行了,例如下面的spring cloud config-server运行,那么会注册一个到总服务里面。