Reputation: 105
I have the necessity to configure a Spring Cloud Config Server for read the properties of the variuos instance from a JDBC Backend (PostgreSQL) instead of Git repository. I follow the official documentation, but doesn't work. I add to application.properties of Spring Cloud Config Server
spring.profiles.active=jdbc
spring.datasource.url= jdbc:postgresql://localhost:5432/example
spring.datasource.username=user
spring.datasource.password=pass
and I create the table inside database
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"
)
and, for the eureka server, I insert
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');
The Eureka Server, if I use this parameters inside Git repository, works fine, but using the JDBC backend, doesn't work. Anyone can help me?
Upvotes: 2
Views: 4024
Reputation: 53
The PSQLException saying "properties" does not exist is because PostgreSQL is case-sensitive. When using PGAdmin to create table/column, the tool automatically adds the quotes if the name is in all caps, thus making it case-sensitive.
You can try the following:
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');
The application.properties contains:
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
You can now access using http://localhost:8888/myconfig/default
Upvotes: 2