springspring-cloudspring-cloud-config

Local property YAML files are not included in a .jar executable files


I've created a config server by Spring Cloud Config. The project looks like this:

src
  - main
    - java
      - com.my.configserver
        - ConfigserverApplication.java
    - resources
      - config
        - my-service
        - my-service-prod.yml
        - my-service-qa.yml
      - application.yml

application.yml looks like this:

spring:
  application:
    name: "configserver"
  profiles:
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/config

If I run the application by the IDE's Run button, the app works fine. This means that the app can access property yml files in src/main/resources/config folder.

However, if I make a .jar file by mvn clean install and run it by java -jar target/configserver-0.0.1-SNAPSHOT.jar, I see the following message:

Monitoring for local config changes: [/config]

Failed to walk directory: /config

java.io.IOException: Cannot register watcher for /config
        at org.springframework.cloud.config.monitor.FileMonitorConfiguration.registerWatch(FileMonitorConfiguration.java:319) ~[spring-cloud-config-monitor-4.2.1.jar!/:4.2.1]

It seems that the app can't access src/main/resources/config folder if it's running in a .jar file. Does anyone know why this happens?


Solution

  • I found the cause.

    I added spring-cloud-config-monitor to pom.xml while I wasn't using the functionality. Removing the dependency from pom.xml solved the problem