Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2: Refresh properties on the fly not working

I have followed this official tutorial Getting Started Centralized Configuration using spring boot 2.0.0.RELEASE and spring cloud Finchley.M8

But refreshing properties on the fly (Without restart) is not working. After Some debugging, I noticed that in method refresh() from ContextRefresher.class, it returns the changed keys correctly, but after reconstructing the bean annotated with @RefreshScope in the next use. It still sees the old value not the updated one.

Note: This was working perfectly with spring boot v 1.5.6 and spring cloud Edgware.RELEASE.

Any help please?

Thanks

like image 372
Mohamed Osama Avatar asked Jan 28 '23 11:01

Mohamed Osama


1 Answers

It seems spring.cloud.config.uri in spring boot 2.0.1.RELEASE always looking for port 8888 and not accepting other values, so I put the below configuration (you can ignore it, as it is the default value for the client, and the server should run on port 8888)

spring:
  cloud:
    config:
      uri: http://localhost:8888

I also tried to expose all other services in the client for testing as follows

management:
  endpoints:
    web:
      exposure:
        include: '*'

or use the following to allow only refresh

management:
  endpoints:
    web:
      exposure:
        include: refresh

Then called POST method not GET for refreshing

$ curl -X POST localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"

Finally, it works.

like image 72
Hany Sakr Avatar answered Mar 05 '23 07:03

Hany Sakr