【发布时间】:2021-05-07 08:27:42
【问题描述】:
我需要通过 PostgreSQL 数据库存储和使用配置。我已向数据库输入以下查询
CREATE TABLE xlabs.properties (
application varchar(200) DEFAULT NULL,
profile varchar(200) DEFAULT NULL,
label varchar(200) DEFAULT NULL,
prop_key varchar(500) DEFAULT NULL,
value varchar(500) DEFAULT NULL,
id SERIAL PRIMARY KEY
);
INSERT INTO xlabs.properties (application, profile, label, prop_key, value) VALUES ('config-server','development','latest','ssn','([0-9]{9})');
所以,在运行配置服务器并点击http://localhost:8090/config-server/development/latest 后将返回此响应。
{"name":"config-server","profiles":["development"],"label":"latest","version":null,"state":null,"propertySources":[{"name":"config-server-development","source":{"ssn":"([0-9]{9})"}}]}
但问题是当我尝试通过云配置客户端使用以下配置使用上述 ssn 属性时,bootstrap.properties
spring.cloud.config.uri=http://localhost:8090
spring.profiles.active=development
management.endpoints.web.exposure.include=*
spring.application.name=config-server
spring.cloud.config.label=latest
和
@RestController
@RefreshScope
public class ConfigController {
@Value("${ssn}")
private String name;
@GetMapping("/message")
public String returnConfig(){
return this.name;
}
}
所以,当我运行项目时,它会给出运行时错误
Could not resolve placeholder 'ssn' in value "${ssn}"
请帮忙。
【问题讨论】:
标签: spring-boot client-server config spring-cloud spring-cloud-config