简体   繁体   English

带有数据库后端的 Spring Cloud Config Server

[英]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.

相关问题 带有 Azure KeyVault 后端的 Spring Cloud Config Server - Spring Cloud Config Server with Azure KeyVault backend 带有Zookeeper或HashiCorp Vault后端的Spring Cloud Config Server - Spring Cloud Config Server with Zookeeper or HashiCorp Vault Backend 如何使用带有 postgresql 和 jdbc 的 Spring Cloud 配置服务器作为具有多个配置文件的后端? - How to use spring cloud config server with postgresql and jdbc as backend with multiple profiles? 将 Spring Cloud Config Server 与 vault 后端集成,在 GET 请求上出现 I/O 错误,连接被拒绝 - Integrating Spring Cloud Config Server with vault backend giving I/O error on GET request with connection refused 带有配置服务器的 Spring Cloud Eureka - Spring Cloud Eureka with Config Server 具有自定义表的Spring Config Server JDBC后端 - Spring Config Server JDBC Backend with custom table 当 Spring Security 在 Spring Cloud Config Server 上处于活动状态时,Spring Cloud Config Client 不获取配置 - Spring Cloud Config Client not fetching config when Spring Security is active on Spring Cloud Config Server 配置Spring Cloud Config Server和Spring Cloud Vault以进行生产 - Configuring Spring Cloud Config Server and Spring Cloud Vault for production Spring Cloud Config服务器显示invalidPrivateKey - Spring Cloud Config server showing invalidPrivateKey Spring 云配置服务器启动失败 - Spring Cloud config server fails to start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM