Cloud config server with external file and spring boot application

I am creating a personal Git repository where I have saved my properties file. I am creating a cloud config server ('my-config-server') and used a Git repository url. I have linked my spring-boot application which needs to access an external properties file with a Git repository.

Problem: Before using the external properties file, my internal properties file was at: src / main / resources and I was accessing it in my application using

@PropertySource("classpath:myproperties.properties)

      

But after using the cloud config server, all the changes I have to make to make my spring-boot application understandable is that now it has to fetch properties from the Git repository?

I added

services
   - my-config-server

      

in manifest.yml I added @EnableConfigServer and @RefreshScope

What else needs to be done? What to do with

 @PropertySource("classpath:myproperties.properties)

      

+3


source to share


1 answer


You have to replace the file with the myproperties.properties

file bootstrap.yml

that gives the url of your git repository:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo

      

Then in the repository you have to rename myproperties.properties

with application.properties

. To access your properties use an annotation @Value

like:



@Value("${my.color}")
private String myColor;

      

Read Spring Cloud Config Link for more details .

+1


source







All Articles