我有一个与从配置服务器加载配置属性相关的问题。 请您检查并告诉我如何加载这些配置.
谢谢。
春季:2.6.2
春季云: 2021.0.0
主要
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication
public class ConfigServerDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerDemoApplication.class, args);
}
}
/resource/application.properties
spring.application.name=demo
spring.cloud.config.enabled=true
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.uri=https://gitlab.com/mama/test-config-server.git
Git 存储库
application.properties
message="HELLO WORLD"
其余控制器
@RestController
@RefreshScope
public class RestMainController {
@Value("${message}")
private String message;
@GetMapping("/index")
public String index() {
return "------->" + message;
}
}
{
"name": "demo",
"profiles": [
"default"
],
"label": null,
"version": "59ff5bd35093e6791eb8f6fb7e23d7915b21e565",
"state": null,
"propertySources": [
{
"name": "https://gitlab.com/mama/test-config-server.git/application.properties",
"source": {
"message": ""HELLO WORLD""
}
}
]
}
错误信息
Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'message' in value "${message}"
你不需要在 " 中保留message
键的值,
application.properties
message=HELLO WORLD
在 Git 上,你的文件名应该是 demo.properties,因为你设置了 "spring.application.name=demo"。
The HTTP service has resources in the following form:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties