Spring Cloud Config JDBC后端

时间:2017-11-28 14:42:13

标签: spring-boot spring-cloud spring-jdbc spring-cloud-config

我有必要配置Spring Cloud Config Server,以便从JDBC后端(PostgreSQL)而不是Git存储库中读取variuos实例的属性。我遵循官方文档,但不起作用。 我添加到Spring Cloud Config Server的application.properties

spring.profiles.active=jdbc
spring.datasource.url= jdbc:postgresql://localhost:5432/example
spring.datasource.username=user
spring.datasource.password=pass

我在数据库中创建表

CREATE TABLE public."PROPERTIES"
(
    "APPLICATION" character varying(500) COLLATE pg_catalog."default",
    "PROFILE" character varying(500) COLLATE pg_catalog."default",
    "LABEL" character varying(500) COLLATE pg_catalog."default",
    "KEY" character varying(500) COLLATE pg_catalog."default",
    "VALUE" character varying(500) COLLATE pg_catalog."default"
)

,对于eureka服务器,我插入

INSERT INTO public."PROPERTIES"
("APPLICATION", "PROFILE", "LABEL", "KEY", "VALUE")
VALUES('discovery-service', '', '', 'spring.application.name', 'discovery-service');
INSERT INTO public."PROPERTIES"
("APPLICATION", "PROFILE", "LABEL", "KEY", "VALUE")
VALUES('discovery-service', '', '', 'server.port', '8761');

Eureka Server,如果我在Git存储库中使用这些参数,工作正常,但使用JDBC后端,不起作用。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

PSQLException说"属性"不存在是因为PostgreSQL区分大小写。使用PGAdmin创建表/列时,如果名称全部为大写,则工具会自动添加引号,从而使其区分大小写。

您可以尝试以下操作:

CREATE TABLE public.properties
(
    application character varying(50) COLLATE pg_catalog."default",
    profile character varying(50) COLLATE pg_catalog."default",
    label character varying(50) COLLATE pg_catalog."default",
    key character varying(50) COLLATE pg_catalog."default",
    value character varying(500) COLLATE pg_catalog."default"
)

INSERT INTO properties
("application", "profile", "label", "key", "value")
VALUES('myconfig', 'default', 'master', 'my.message', 'hello');

application.properties包含:

server.port=8888
spring.profiles.active=jdbc
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url= jdbc:postgresql://localhost:5432/configdb
spring.datasource.username=xxxxxx
spring.datasource.password=xxxxxx

您现在可以使用http://localhost:8888/myconfig/default

进行访问