我有一個與從 config-server 加載配置屬性相關的問題。請您檢查并建議我如何加載這些配置。
謝謝你。
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.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}"
uj5u.com熱心網友回復:
您不需要為message“”中的鍵保留值,
application.properties
message=HELLO WORLD
uj5u.com熱心網友回復:
在 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/399186.html
