[英]Spring Cloud Config Server with Database backend
I am trying to create a Spring Cloud Config Server that gets its Configurations from a database
and not from the default git-repo.我正在尝试创建一个 Spring Cloud Config Server,它从
database
而不是从默认的 git-repo 获取其配置。
Every time I try to run my Config Server Application I get this Error:每次我尝试运行我的配置服务器应用程序时,我都会收到此错误:
Execution failed for task ':config-server:applications:config-server:bootRun'.
> Process 'command 'C:\Program Files\choco\openjdk-jdk-11\latest\bin\java.exe'' finished with non-zero exit value 1
From the Server itself comes this message (reformatted for better reading):来自服务器本身的消息(重新格式化以便更好地阅读):
[ERROR agnostics.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description: Invalid config server configuration.
Action: If you are using the git profile, you need to set a Git URI in your configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
[main||||||| - |]]
My application.yaml has this part in it:我的 application.yaml 中有这部分:
spring:
application:
name: my-services-api
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
platform: h2
hikari:
connection-timeout: 5000
maximum-pool-size: 10
cloud:
config:
server:
jdbc:
sql: SELECT KEY, VALUE from MY_PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?
order: 1
h2:
console:
enabled: true
As you can see, there is no spring.cloud.config.server.bootstrap=true
so I don't know what it wants me to do.如您所见,没有
spring.cloud.config.server.bootstrap=true
所以我不知道它想让我做什么。
I also don't want to use a git profile, so the Action doesn't help me at all.我也不想使用 git 配置文件,所以 Action 根本没有帮助我。
Does someone know, how I can fix this issue?有人知道,我该如何解决这个问题? Thanks
谢谢
Update: I added spring.cloud.config.server.git.uri
and changed the order of jdbc to 1 and of git to 2.更新:我添加了
spring.cloud.config.server.git.uri
并将 jdbc 的顺序更改为 1,将 git 的顺序更改为 2。
After that it kind of worked but I still have the issue, that it won't read the configurations from the database之后它有点工作但我仍然有问题,它不会从数据库中读取配置
I was trying to debug your issue and I have following settings and could successfully start the server as well as query the API.我正在尝试调试您的问题,我有以下设置,可以成功启动服务器以及查询 API。
#bootstrap.yml
spring:
application:
name: my-services-api
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
platform: h2
hikari:
connection-timeout: 5000
maximum-pool-size: 10
profiles:
active: jdbc
cloud:
config:
server:
jdbc:
sql: "SELECT properties.key, properties.value from properties where application=? and profile=? and label=?"
order: 1
h2:
console:
enabled: true
Also I have put the schema.sql and data.sql into classpath ( resources folder of maven project) so that they autopopulate the data into embedded h2 database.此外,我已将 schema.sql 和 data.sql 放入类路径(maven 项目的资源文件夹)中,以便它们将数据自动填充到嵌入式 h2 数据库中。
#schema.sql
DROP TABLE IF EXISTS PROPERTIES;
CREATE TABLE PROPERTIES (
id INT AUTO_INCREMENT PRIMARY KEY,
APPLICATION VARCHAR(25) NOT NULL,
PROFILE VARCHAR(25) NOT NULL,
LABEL VARCHAR(25) DEFAULT NULL,
KEY VARCHAR(25) NOT NULL,
VALUE VARCHAR(200) NOT NULL
);
#data.sql
INSERT INTO PROPERTIES( APPLICATION, PROFILE, LABEL, KEY, VALUE)
values('myapp', 'MYCLIENT', '1.1', 'prop1', 'val11');
INSERT INTO PROPERTIES( APPLICATION, PROFILE, LABEL, KEY, VALUE)
values('myapp', 'MYCLIENT', '1.1', 'prop2', 'val12');
INSERT INTO PROPERTIES( APPLICATION, PROFILE, LABEL, KEY, VALUE)
values('myapp', 'MYCLIENT', '1.1', 'prop3', 'val13');
INSERT INTO PROPERTIES( APPLICATION, PROFILE, LABEL, KEY, VALUE)
values('myapp', 'MYCLIENT', '1.0', 'prop1', 'val21');
INSERT INTO PROPERTIES( APPLICATION, PROFILE, LABEL, KEY, VALUE)
values('myapp', 'MYCLIENT', '1.0', 'prop2', 'val22');
INSERT INTO PROPERTIES( APPLICATION, PROFILE, LABEL, KEY, VALUE)
values('myapp', 'MYCLIENT', '1.0', 'prop3', 'val23');
And I could successfully start and query the Config server我可以成功启动和查询配置服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.