How to give the uri in windows for Spring Cloud Config with Local Git repo? - spring

I am trying to set up Spring Cloud Config Server. How to give the spring.cloud.config.server.git.uri in application.properties for Windows?
The uri is this one
D:\MicroservicesProject\git-localconfig-repo\test-service.properties
I tried this
spring.cloud.config.server.git.uri=D:\\MicroservicesProject\\git-localconfig-repo\\limits-service.properties
But I am getting this error
Caused by: org.eclipse.jgit.errors.TransportException: D:\MicroservicesProject\git-localconfig-repo\limits-service.properties: not a bundle

Try updating config line as follows:
spring.cloud.config.server.git.uri=file:///C:/Users/win10/Desktop/git-localconfig-repo/

I found the solution by making the path to the directory without specifying the name of the file.
D:\\MicroservicesProject\\git-localconfig-repo

Related

How to configure Spring Cloud Config Server to use cloned configuration files

My application.properties files of my Cloud Config Server looks like this.
config.source=Local Cloud Server #just to check where config come from
server.port=8012
encrypt.key=xxxxxxxxxxxxxx
spring.profiles.active=staging
spring.application.name=my-config-server
# Git Backend
spring.cloud.config.server.git.username=MY_USERNAME
spring.cloud.config.server.git.password=ghp_MY-DEV-ACCESS-TOKEN
spring.cloud.config.server.git.uri=https://github.com/my-username/app-config
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.basedir=file://${user.dir}/cloned_configurations
On startup a new folder "cloned_configuration" is created inside of Cloud Config Server folder. I see all of my propertie files cloned form github with correct values.
But for some reason none of these are used. For e.g config.source must have the value "GitHub" because the cloned application.repository has an entry
config.source=GitHub
But on application start I see "Local Cloud Server". All other settings are also not used from cloned properties.
With Postman I can receive all Configs without any issues. But none of theme are used by my Config Server or any of my other webservices.All webservices and the config server using their own application.properties file.
What I do wrong?
You probably need to move your config server properties into your bootstrap.properties file instead of application.properties.
spring.cloud.config.server.git.username=MY_USERNAME
spring.cloud.config.server.git.password=ghp_MY-DEV-ACCESS-TOKEN
spring.cloud.config.server.git.uri=https://github.com/my-username/app-config
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.basedir=file://${user.dir}/cloned_configurations
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_client.html

SpringBoot Config Server file separator issue

I have configued Spring Boot Config server (2.4.1 version) integrated with Git repository.
Config looks valid, there is no issue during loading files from git, however when i point to
localhoast:port/application/dev
i get
{"name":"application","profiles":["dev"],"label":null,"version":"7e67e69e075b05d9fa50e3255deef7585ed658c7","state":null,"propertySources":[]}
I turned on logging everything and I discovered, that config server downloaded file correctly and saved file somewhere in temp folder like:
(1) C:/Users/username/AppData/Local/Temp/config-repo-5493381163789847226/
however NativeEnironmentRepository is expecting that it will be in:
(2) C:\Users\username\AppData\Local\Temp\config-repo-5493381163789847226\
which is also valid windows path.
When I turn on debuggin I found out that
NativeEnvironmentRepository check path (1)
against pattern (2) and it fails. So in result
"propertySources":[]
is empty.
Is this a bug on SpringBoot config server? or should I setup/change something in configuration?
It looks like NativeEnvironmentRepository should use system File.separator...
I had same issue with spring boot 2.4.1 in windows platform. It is solved by spring 2.4.2.snapshot.
Spring 2.4.1 worked properly in linux ubuntu. I dont know what is the problem.

Spring Cloud Config Server Not picking changes

I am trying to setup spring config cloud using local file system.
Below is my config on cloud server.
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=classpath:/
Bootstrap.properties on client app is as shown below
spring.application.name=hello-world
spring.cloud.config.uri=http://localhost:8888
management.endpoints.web.exposure.include=*
I have also created hello-world.yml on class path for the hello-world spring boot application with property, test: Hello World
Followed below steps to make use of config server.
Step 1: Update the config file and start cloud config server. Able to
see config http://localhost:8888/hello-world/default
Step 2: Start client app hello-world, client app able to read the
test property file from cloud config server.
Step 3: Make changes to config by updating test: Good Bye on
hello-world.yaml.
At this moment, if I check
http://localhost:8888/hello-world/default ,it still shows old value.
Step 4: Run /actuator/refresh on client app. But it won't detect
any change on config server.
The new changes are reflected only if I restart the cloud config server.
Is there any configuration issue causing the cloud config server to unable to listen to changes ?
I could see o.s.cloud.commons.util.InetUtils : Cannot determine local hostname INFO log on cloud config app.
First of all I followed the same exact steps you followed and got the same issue, after almost day of search and study on the matter found out the followings,
we shouldn't use classpath:/<whatever> for
spring.cloud.config.server.native.searchLocations
because when we use so and build the project and run the location refers to the directory inside the generated .jar file, so we will not be able to update it in runtime.
To confirm this you can stop config server, open you .jar archive and delete hello-world.yml file then try http://localhost:8888/hello-world/default you will get default null responses
So we have to use some other locations for spring.cloud.config.server.native.searchLocations either with full directory path or just directory from app running location
Examples
For full path in windows use file:///full-path
spring.cloud.config.server.native.searchLocations: file:///E:\configs
Just for a directory (which will search project root directory if you running from IDE, if running jar then target directory or jar location spring.cloud.config.server.native.searchLocations: configs
spring.cloud.config.server.native.searchLocations: configs\whatever
we can configure multiple locations too as follows, spring.cloud.config.server.native.searchLocations: file:///E:\configs, configs

Spring Cloud Config Server NoSuchLabelException: No such label: master [duplicate]

I have a simple Spring Cloud Config Server which consume configuration from git server.
ConfigServer bootstrap.yml :
spring:
application:
name: config-service
cloud:
config:
server:
git:
uri: ssh://git#mydomain:myport/myrepo.git
searchPaths: "configurations/{application}/{profile}"
server:
port: 8888
When I deploy ConfigServer on local, I can retrieve configuration from http://localhost:8888/myapp/test. But when I deploy ConfigServer on test server, it throws No such label: master when I hit http://testserverip:8888/myapp/test.
Any help would be most appreciated!
I know that I'm posting this answer very very late. But, still posting it so that other folks can find this helpful. Now a days, default branch name of GitHub is "main", but Spring Cloud Config still looks for "master" as a label name. So, if you want to change the default behavior, you can always change the label name look up using below property in application.yml or application.properties:
spring.cloud.config.server.git.default-label=main
This worked very well for me. I'm using Spring Boot 2.3.6.RELEASE
GitHub created default branch "main" , however Spring cloud Config was looking for "master branch". I have created a "master" branch and it worked!
I faced this same annoying scenario.
I'll first state how I solved this scenario and will later emphasize my mistakes which I did in my previous approaches.
In my context, I'm using application.properties
My application overview looks like below:
I have a config-server which is centralized & provides the respective configuration data to the respective micro-services.
For instance, a micro-service 'limits-service', requires some configuration data, it gets it from the central configuration server('spring-cloud-config-server').
Hence to achieve this, 'limits-service' queries the central config server which in-turn fetches the requested data from a remote git branch('spring-cloud-samples').
┌---------------------- <--> [currency-exchange-service]
[git] <--> [spring-cloud-config-server] ------- <--> [limits-service]
└---------------------- <--> [currency-conversion-service]
Solution:
I simply created a new Git Repository (spring-cloud-samples) for all the configuration files which would be consumed by several micro-services through a central configuration server.
In the application.properties file of central configuration server('spring-cloud-config-server'), I have provided a property as:
spring.cloud.config.server.git.uri=https://github.com/{username}/{git-reponame.git}
which might look like
spring.cloud.config.server.git.uri=https://github.com/alice123/spring-cloud-samples.git
That's it!
On starting my central-config-server & observe the log which is as follows:
2020-02-17 05:25:07.867 INFO 15000 --- [nio-8888-exec-9] o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/D:/Users/{userName}/AppData/Local/Temp/config-repo-3453413414/limits-service.properties
Moreover, I also consumed the config-data through my 'limits-service' & it worked like a charm!
I tried the following things that resulted in failures and a lot of screaming & yelling. XD
I'm posting it, just so that someone who's trying this same concept might save a night's work or maybe less :p
1) Initially, I was using my Git Repositories SSH URL in my application.properties file of central-config-server like follows:
spring.cloud.config.server.git.uri=git#github.com:alice123/spring-cloud-samples.git
spring.cloud.config.server.git.username=alice123
spring.cloud.config.server.git.password=alice123Pwd
which resulted in the following error:
2020-02-17 05:22:45.091 WARN 15000 --- [nio-8888-exec-1] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.TransportException: git#github.com:aniketrb-github/spring-cloud-samples.git: Auth fail
2) Later, I tried to read the config data from a native/local git directory, which was pointing to my Git remote branch(spring-cloud-samples)
Then I provided the following in my application.properties file:
spring.cloud.config.server.git.uri=file://D:\aniket-workspace\github-ws\microservices\udemy-microservices\git-localconfig-repo
This crashed with:
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.properties'
3) Later after enough googling, I changed the above property to below which worked!!:
spring.cloud.config.server.git.uri=D:\\\\alice-workspace\\\\github-ws\\\\microservices\\\\git-localconfig-repo
The 'limits-service' eventually failed while it tried to get the config-data from 'spring.cloud.config.server' with following error:
404: Not Found - "org.springframework.cloud.config.server.environment.NoSuchLabelException: No such label: master"
The solution I've stated worked for me due to all the failures I came across which I mentioned above.
Please correct me if I'm wrong & improvise if necessary. I hope this helps and saves some crucial time.
References: spring-cloud-config, https-or-ssh, git-ssh-windows, git-ssh-windows-troubleshooting
This happens when your service cannot access to Git repository.
Since you can start your application, I assume test server can reach to Git. You should set up SSH authentication to your Git server. You can check this site for SSH configuration.
In my case nothing of given answers worked. only thing that worked is setting default-label to master
spring.cloud.config.server.git.default-label=master
When you create a new repository, nowdays git makes "main" as the default branch instead of master. This issue is all about this.
Create "master" branch manually. It will solve all these issues.
for me this caused due to my default branch 'main'. whenever you create a new branch the default branch is 'main' not 'master' anymore. but spring server config look for master branch.
the quick solution is to checkout a new branch called 'master' from 'main' branch. and try from spring config server. thats it.
to create a new branch from main branch. first point to main branch and from there
git checkout -b master
git push --set-upstream origin master
restart your config server and test
I hope you are doing well.
I am using STS 4 and added source link folder (local git repo) for spring cloud configuration from local git repo.
I had facing same issue,
I did just change back slashes with forward slashes.
when i was using like this
spring.cloud.config.server.git.uri=file://C:\Users\coder\Desktop\spring material\in28microservies\git-localconfig-repo
I got error
2020-04-04 14:57:37.874 ERROR 6952 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot load environment] with root cause
java.lang.IllegalStateException: Cannot convert uri to file: file://C:UserscoderDesktopspring materialin28microserviesgit-localconfig-repo
Then i just replaced all back slashes with forward slashes in config server properties file, and it worked for me
spring.cloud.config.server.git.uri=file://C:/Users/coder/Desktop/spring material/in28microservies/git-localconfig-repo
spring.profiles.active=native
spring.cloud.config.server.native.searchLocations=file://<location>
Try this as mentioned by our friend below:
https://stackoverflow.com/a/33179106/1908827
This will work for sure !!! :)
1 ) You have to commit your changes in following way to show up the master if you initialize the repo for first time in that particular folder
> git add -A .
> git commit -m "added prop..."
2) re-run the project and hit same url.
Njoy :)
This is what I found when I too had a similar issue.
Issue/Mistake#1 >> I created the properties file using notepad(I am on Windows OS).
The file was created with .txt extension. Hence the cloud config was not picking up the changes.
Fix: changed the extension from .txt to .properties
Issue/Mistake#2 >> The .properties file name was different from what is mentioned.
The file should be named:
servicename.properties
matching the servicename defined in the *application.properties* as below:
spring.application.name=<<servicename>>
In my example:
spring.application.name=limits-service
Hence the file should be named **limits-service.properties**,
but I created with the name limits-service-service.properties
enter code here
Fix: renamed the file to: limits-service.properties
Now I am able to see the configurations from the spring-cloud-config and it is picking the values from the configured GIT repository.
To those who may have a 'delayed(>2mins) but correct response' when visiting: localhost:8888/limits-service/default, One simple way that works for me is:
In limits-service.properties, change the configserver port to 8887 instead of sticking with 8888:
spring.config.import=optional:configserver:http://localhost:8887
It appears that there is a timeout when Spring is trying to visit port 8888.
In application.properties of spring-cloud-config-server, change spring.cloud.config.server.git.uri directly to a REAL git that is stored on Github. I am using my own public git so that you guys can copy-paste it:
spring.cloud.config.server.git.uri=https://github.com/SimonSongCA/git-localconfig-repo.git
It significantly reduces the delay from X minutes to seconds, and there are no exceptions at the console anymore.
The below solution worked for me.
Add below property in properties file.
spring.cloud.config.server.git.default-label=master
Also check to see if you are pointing to right git location
spring.cloud.config.server.git.uri=file:///C://Work//my_project//app-props//repo//test
The above error comes when you refer to old tutorial because GitHub switched to the default branch as "main" then your application tries to access the master branch of your config-server repository but it is not available so above error comes and when you access though browser it will display white label error page.
solution already mentioned in above comments

Spring Cloud Config Server - How to download binary file

I have a Spring Cloud Config Server with the usual properties files in the git repo:
|--application.yml
|--app1.yml
I also added a binary file
|--mybinaryfile
Normally to access the properties I would ask for
http://myconfigserver/app1/dev
Is it possible to download the binaryfile through the config server? I have tried with
http://myconfigserver/mybinaryfile
and
http://myconfigserver/mybinaryfile/dev
but they didn't work.
I found it:
http://myconfigserver/*/dev/master/mybinaryfile

Resources