Skip to content
Advertisement

EnableConfigServer is not working for native location in spring boot

I am trying to configure a configuration server for all the properties in our application using @EnableConfigServer in spring boot. Please see the code below :

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

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

}

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 http://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.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.cdk.config</groupId>
    <artifactId>configserver</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>configserver</name>
    <description>Contains all the configurations/properties required by all the services</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </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>
        </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>

application.properties

spring.application.name=config-server
server.port=9090
spring.cloud.config.server.native.searchLocations=file://Users/Sankest/StarterProjects/MicroServices/AllConfigurations/
spring.profiles.active=native

Copied all the property files to : /Users/Sankest/StarterProjects/MicroServices/AllConfigurations/

But when I try to access url at http://localhost:9090/config-server/default I am not seeing any property files and getting the following response:

{"name":"config-server","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[]}

Advertisement

Answer

  1. Correct value should be spring.cloud.config.server.native.searchLocations=file:///Users/Sankest/StarterProjects/MicroServices/AllConfigurations/ with 3 front slashes after file:. One way to verify whether path is correct or not, even without running the application, is to paste the path in browser and check whether it shows all the files.
  2. For default profile make sure either file name is application.yml or application.properties.
  3. For other profiles e.g. dev, file name should be application-dev.yml or application-dev.properties (if all are in the same folder), then http://localhost:9090/config-server/dev would show both dev and default profile entries.
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement