Ezop
Ezop

Reputation: 31

Spring cloud config searchPaths vs repo directory structure

I'm trying to run Spring Cloud Config server (centralized-configuration-service) with remote repository on Git (Bitbucket). But no matter what searchPaths I'm setting in application.properties, it's always returning empty array instead of values on repository.

So, my repository looks like this (on master branch):

app1/ (dir)
  app1.yml
  app1-test.yml
  app1-uat.yml
  ...
app2/ (dir)
  app2.yml
  app2-test.yml
  app2-uat.yml
  ...

My src/main/resources/application.properties:

server.port=8888
spring.cloud.config.server.git.uri=https://bitbucket.repo.url/repo.git
spring.cloud.config.server.git.cloneOnStart=true
spring.cloud.config.server.git.force-pull=true
spring.cloud.config.server.git.skipSslValidation=true
spring.cloud.config.server.git.username=repo_login
spring.cloud.config.server.git.password=repo_pass
spring.cloud.config.server.git.searchPaths='{application]' # Tried also '{application}/{application}-{profile}' and '{application}/{application}-{profile}.yml'
spring.security.user.name=config_user
spring.security.user.password=config_pass

src\main\java\example\centralizedconfigurationservice\ConfigServer.java:

package example.centralizedconfigurationservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
    
    public static void main(String[] arguments) {
        SpringApplication.run(ConfigServer.class, arguments);
    }
}

pom.xml:

<?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.5.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>example</groupId>
    <artifactId>centralized-configuration-service</artifactId>
    <version>1.0.0</version>
    <name>centralized-configuration-service</name>
    <description>Desc...</description>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
   <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-test</artifactId>
     <version>2.1.7.RELEASE</version>
   </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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>  
        </plugins>
    </build>
</project>

I'm starting server with mvnw

./mvnw spring-boot:run

logs from starting server:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.2)

2021-07-20 13:51:32.444  INFO 35 --- [           main] p.c.p.n.c.ConfigServer                   : Starting ConfigServer using Java 11.0.1 on 67421f38de7b with PID 35 (/app/target/classes started by root in /app)
2021-07-20 13:51:32.449  INFO 35 --- [           main] p.c.p.n.c.ConfigServer                   : No active profile set, falling back to default profiles: default
2021-07-20 13:51:33.311  INFO 35 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3aa36d2a-4db1-39bb-8278-6d749acb1c11
2021-07-20 13:51:33.582  INFO 35 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
2021-07-20 13:51:33.594  INFO 35 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-20 13:51:33.594  INFO 35 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.48]
2021-07-20 13:51:33.693  INFO 35 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-07-20 13:51:33.693  INFO 35 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1151 ms
2021-07-20 13:51:34.124  INFO 35 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@228bda54, org.springframework.security.web.context.SecurityContextPersistenceFilter@5de5e95, org.springframework.security.web.header.HeaderWriterFilter@314b9e4b, org.springframework.security.web.csrf.CsrfFilter@40d23c82, org.springframework.security.web.authentication.logout.LogoutFilter@34c70b5e, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@42383cb0, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@4f2d995e, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@75b6dd5b, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@d2e6b0b, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@303c55fa, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@7c2924d7, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@b3e86d5, org.springframework.security.web.session.SessionManagementFilter@51dae791, org.springframework.security.web.access.ExceptionTranslationFilter@949c598, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@7316523a]
2021-07-20 13:51:35.979  INFO 35 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
2021-07-20 13:51:36.000  INFO 35 --- [           main] p.c.p.n.c.ConfigServer                   : Started ConfigServer in 4.043 seconds (JVM running for 4.525)

and when I try get 'http://localhost:8888/app1/test' im getting (after logging in):

{"name":"app1","profiles":["test"],"label":null,"version":"f4e9867b34eacdc03bbd5478c12cf64fbadcb867","state":null,"propertySources":[]}

Anyone knows what searchPaths should I set to get it working?

Upvotes: 1

Views: 1538

Answers (1)

Ezop
Ezop

Reputation: 31

I got it working using by switching from application.properties to application.yml and setting:

spring:
  cloud:
    config:
      server:
        git:
          uri: ...
          searchPaths:
            - '*/**'

Upvotes: 2

Related Questions