3

I am trying to create a Spring Cloud Config Server that gets its Configurations from a database and not from the default 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:

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.
I also don't want to use a git profile, so the Action doesn't help me at all.

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.
After that it kind of worked but I still have the issue, that it won't read the configurations from the database
I started from scratch, did the same thing and then it worked fine

BeeTheKay
  • 319
  • 2
  • 15
  • Can you show application-jdbc profile's config ? – Dhaval Goti Jul 12 '21 at 07:40
  • @DhavalGoti Sorry, forgot to take that out, I don't have a jdbc profile – BeeTheKay Jul 12 '21 at 07:52
  • this url can help you - https://www.devglan.com/spring-cloud/jdbc-backend-spring-cloud-config – Dhaval Goti Jul 12 '21 at 07:57
  • @DhavalGoti that gives me the exact same Error message – BeeTheKay Jul 12 '21 at 08:04
  • Setting the bootstrap and you need to use the composite configuration, just like the action requires. https://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.2.0.RELEASE/reference/html/#composite-environment-repositories – D.T Jul 12 '21 at 14:39
  • Another guy of our team made a Spring Cloud Config Server from scratch and it worked. We haven't found out what the issue was but redoing it worked – BeeTheKay Feb 08 '22 at 12:26

2 Answers2

2

I was trying to debug your issue and I have following settings and could successfully start the server as well as query the API.

My maven build config file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.test</groupId>
    <artifactId>config-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config-server</name>
    <description>Test Config Server</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>       
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.200</version>         
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

The main class

@EnableConfigServer
@SpringBootApplication
public class ConfigserverApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigserverApplication.class, args);
    }

}
#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.

enter image description here

#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');

enter image description here

And I could successfully start and query the Config server

enter image description here

Shailendra
  • 8,874
  • 2
  • 28
  • 37
  • Hey, I copied your code and tried it in my application, but I always get a 404 Not Found instead of the JSON data... – BeeTheKay Aug 09 '21 at 07:39
  • What is the url you are trying to hit ? – Shailendra Aug 09 '21 at 13:03
  • I can not start the config server without a git uri and if I have one, it just sais "No credentials provider required for URI *[insert uri]*" So if I don't have the git uri, it won't start and if I have one, it won't correctly run – BeeTheKay Aug 09 '21 at 13:48
  • 1
    I have added the main class as well which I am using to start the project. There is no other java class apart from this one. – Shailendra Aug 09 '21 at 14:31
1

Your application.yaml file is missing below property: spring: profiles: active: jdbc

I have implemented similar kind of project for Cloud config server with JDBC backend and below is the reference: https://github.com/Santhoshinftech/cloud-config-custom-svc