Spring Cloud configuration server not working with local properties file

I played with the Spring Cloud project on github located here: https://github.com/spring-cloud/spring-cloud-config

However, I ran into some problems forcing it to read the local properties file instead of retrieving properties from github. It seems that Spring is ignoring the local file, even when I delete all links to github. A similar question is posted here: Spring-Cloud configuration server ignores configuration properties file

But I have not seen good answers yet. I am wondering if anyone can give me an example of this? I would like to set my properties locally and not use any kind of git repo. I suppose someone has come across this before, and if there is an example of this somewhere, I really would like to see it so that I can move in the right direction.

+14
source share
9 answers

All my code is here https://github.com/spencergibb/communityanswers/tree/so27131143

Src / main / java / application.java

@Configuration @EnableAutoConfiguration @EnableConfigServer public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 

Src / core / resources / application.yml

 spring: application: name: myconfigserver profiles: active: native my: property: myvalue 

Src / main / resources / myapp.yml

 my: otherprop: myotherval 

To get properties for an application named myapp , follow these steps:

curl http://localhost:8080/myapp/default

 { "name": "default", "label": "master", "propertySources": [ { "name": "applicationConfig: [classpath:/myapp.yml]", "source": { "my.otherprop": "myotherval" } }, { "name": "applicationConfig: [classpath:/application.yml]", "source": { "spring.application.name": "myconfigserver", "spring.profiles.active": "native", "my.property": "myvalue" } } ] } 
+17
source

I can read the configuration for apple-service (Test Micro Service) using the Spring configuration server.

Spring config application application.yml example

 spring: profiles: active: native cloud: config: server: native: searchLocations: classpath:config/ server: port: 8888 endpoints: restart: enabled: true 

Put your .properties or .yml files in the src \ main \ resources \ config folder. Make sure that the name of this file should match spring.application.name of your microservice.

For example, if spring.application.name = apple-service , then the properties file should be apple-service.properties in src \ main \ resources \ config .

Example bootstrap.yml apple-service:

 spring: application: name: apple-service cloud: config: uri: http://localhost:8888 
+7
source

Using spring.profiles.active = native is what Spring documentation offers, but I couldn't get it to work. My application.properties file

 server.port=8888 spring.cloud.config.profiles=native 

but the answer is from the url

 http://localhost:8888/config-server/env 

there is

 {"name":"env","label":"master","propertySources":[{"name":"https://github.com/spring-cloud-samples/config-repo/application.yml","source":{"info.url":"https://github.com/spring-cloud-samples","info.description":"Spring Cloud Samples"}}]} 

which indicates that the native profile has been ignored and the server is still considering github as the source of the resource.

The little additional problem I encountered is the default port for the configuration service. According to the Sprint Cloud Config documentation, it should be 8888. If I remove server.port = 8888 from my .properties applications, then the configuration server starts on port 8080, which by default is Spring Boot port, but not the one that should use one server configurations.

+2
source

I had the same issue when starting the configuration server on Mac OS. This did not happen on Linux or Windows.

I had a native property in the bootstrap.yml file:

 spring: profiles: active: native 

Finally, the way it worked for me on a Mac was to pass the active profile to a jar file, for example.

 java -jar config-server.jar --spring.profiles.active=native 

I still don’t know why it works differently on Mac OS.

+2
source

The configuration server will read the local properties files if the application.properties the configuration server contains:

 spring.profiles.active=native **spring.cloud.config.server.native.searchLocations=file:/source/tmp** 

in the /source/tmp , you store the local property file for the client, for example:

 http://localhost:8888/a-bootiful-client/default 

You'll get:

 {"name":"a-bootiful-client","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[{"name":"file:/source/tmp/a-bootiful-client.properties","source":{"message":"Kim"}}]} 
+2
source

I managed to get it to work with the local repo and boot configuration:

 java -jar spring-cloud-config-server-1.0.0.M3-exec.jar --spring.config.name=bootstrap 

The bootstrap.yml file is placed in a folder. / config /.

 server: port: 8080 spring: config: name: cfg_server cloud: config: server: git: uri: /home/us/config_repo searchPaths: pmsvc,shpsvc 
+1
source

I had the same problem on my local machine, but it works fine on my remote server.

@Oreste's answer works for me. So I checked the error log again and found

  2018-06-25 16:09:49.789 INFO 4397 --- [ main] tpasapi.user.UserServiceApplication : The following profiles are active: someProfileISetBefore 

So, the main reason for my case is that I previously set the environment variable, but forgot to delete it. And this overrides the configuration of the application properties files.

I hope you do not make a stupid mistake like me. Fixed:

  unset spring_profiles_active 
0
source

I had this problem on a Mac when there is a space in the file path:

 spring.cloud.config.server.native.search-locations=file:///Users/.../Development/Folder with a space /prj 

Also note that there are 3 slashes in front of users:

 spring.cloud.config.server.native.search-locations=file:///Users/... 

or I use:

 spring.cloud.config.server.native.search-locations=file://${user.home}/Desktop 

Own property:

 spring.profiles.active=native 
0
source

Here is what I did:

next https://medium.com/@danismaz.furkan/spring-cloud-config-with-file-system-backend-c18ae16b7ad5

1) !! do not forget your virtual machine settings !!:

 -Dspring.profiles.active=native 

(in Netbeans: configserver-> project-> properties> Run-> virtual machine settings

2) Either in application.properties

 #spring.cloud.config.server.native.searchLocations=file:///C:/tmp/config spring.cloud.config.server.native.searchLocations=classpath:/config 

or application.yml

 spring: cloud: config: server: native: search-locations : file:///C:/tmp/config #search-locations : classpath:/config 

Note:

n1: search-location and searchLocations work

n2: file: /// => hard file path

how

 c:/temp/config/ app-admin.yml app-admin-develop.yml .... 

n3: for your profile configuration files

Classes Path: /

how

 Other sources/src/main/resources/config/app-admin.yml 

n4: I could not get the file paths working without setting the vm parameters. Do not forget! Just setting spring.profiles.active = native in your application configuration won't help me

n5: http request example

http: // localhost: 8998 / app-admin / default / yml

gives app-admin.yml

http: // localhost: 8998 / app-admin / develop / yml

gives app-admin -velop.yml

0
source

Source: https://habr.com/ru/post/977846/


All Articles