我有一个与从配置服务器加载配置属性相关的问题。请您检查并建议我如何加载这些配置。
谢谢。
JDK: 11
春季: 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.gitGit Repo
application.properties
message="HELLO WORLD"Rest控制器
@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}"发布于 2021-12-29 08:58:29
您不需要在"“中保留message键的值,
application.properties
message=HELLO WORLD发布于 2021-12-29 09:20:16
在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}.propertieshttps://stackoverflow.com/questions/70517085
复制相似问题