【发布时间】:2021-01-12 19:15:30
【问题描述】:
我是 Spring Cloud 的新手,我正在尝试使用存储在 github 上的属性文件连接服务器和客户端。
我的服务器application.yml文件配置如下:
---
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/JonEasy/pluralsight-spring-cloudconfig-wa-tolls.git
#username: uname
#password: pass
search-paths:
- 'station*'
repos:
perf:
pattern:
- '*/perf'
uri: https://github.com/JonEasy/pluralsight-spring-cloudconfig-wa-tolls-perf.git
search-paths:
- 'station*'
github repos 链接在这里 Main Properties 和 Alternative Properties
我的客户端应用程序具有以下设置
spring.application.name=s1rates
spring.profiles.active=default
spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.enabled= true
其余控制器是:
@Controller
public class RateController {
@Value("${rate}")
String rate;
@Value("${lanecount}")
String lanecount;
@Value("${tollstart}")
String tollstart;
@RequestMapping("/rate")
public String getRate(Model m) {
m.addAttribute("rateamount", rate);
m.addAttribute("lanes", lanecount);
m.addAttribute("tollstart", tollstart);
//name of the view
return "rateview";
}
}
所有 ${variables} van 都可以在 git 存储库中的属性文件中找到。
服务器运行正常,但客户端给我以下错误
创建名为“rateController”的 bean 时出错:注入 autowired 依赖失败;嵌套异常是 java.lang.IllegalArgumentException:无法解析占位符 值“${rate}”中的“率”
另请注意,我的 spring 应用程序名称“s1rates”与我的主存储库中的属性文件相匹配,位于 station1/s1rates.properties 下。
有什么提示吗?
【问题讨论】:
-
您确定您的客户端实际连接到配置服务器吗?
-
我认为原因是我缺少引导程序依赖...
标签: java spring client-server spring-cloud spring-framework-beans