question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Cloud Refresh event does not recognize removed properties?

See original GitHub issue

See http://stackoverflow.com/questions/38932168/spring-cloud-refresh-event-does-not-recognize-removed-properties please

Overview

I have a Spring Boot 1.4/1.5 application running with Spring Cloud. My app is using the native profile to pull settings from an external config.properties file. The config server is embedded inside the same application.

In the config.properties file I have added the following setting:

app.setting=helloworld

What works:

When I change the property and send a REFRESH event, relevant beans marked are reloaded and the change is recognized correctly.

What doesn’t work:

If I actually remove the property from config.properties, (by commenting it out for instance), the REFRESH event does nothing to actually refresh the application. Spring Cloud seems to not recognize the fact that the property is removed and when the data-binder proceeds to update the state of the world it misses the fact that the property is removed, and the corresponding bean linked to it must also be refreshed and its field set to blank/null, etc.

It looks like the data-binder only looks at what is at the moment available in the configuration and does not keep record of what was vs what is.

The only way to actually disable that setting in the bean configuration state is not by removing it, but by actually setting it to a blank value (which is a new value, given the setting is just a String). Note the field in Java bean mapped to this property has no default value other than null, and the value is not defined anywhere else (as in an embedded application.properties file, etc)

What might I be missing?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
teggrcommented, Mar 6, 2017

I’ve run into a similar issue when refreshing an external config.properties file. The issue manifested itself with my config.properties because it only had a single entry in it.

To demonstrate:

Start by overriding the application properties

application.properties

some.value=abc

config.properties

some.value=xyz

Initially, using some.value will render “xyz”

To show that the value can be updated, change the value in the config.properties

config.properties

some.value=123

Using the /refresh endpoint, refresh the context and then using some.value will render “123”

Now, by removing the property, then we can see the value does not get updated

config.properties

// now empty

Using the /refresh endpoint, refresh the context and then using some.value will still render “123”. It hadn’t recognised that the field had been removed, nor used the “abc” value from the application.properties.

The issue stems from the class ConfigFileApplicationListener which on line 428, identifies the properties file as empty, so doesn’t load the file into the property sources that are later used to compare the new properties to the old in the ContextRefresher class. The scenario appears to keep the old one in memory.

To workaround this issue, when you only have a single property, you could add property like a.b which would force the file to be loaded with the no value and result in the correct functionality.

config.properties

a.b=true
// item removed, but use some property to make sure it's read later

Hope this helps

0reactions
mmoayyedcommented, Mar 6, 2017

Thanks very much for sharing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud Refresh event does not recognize removed ...
Spring Cloud seems to not recognize the fact that the property is removed and when the data-binder proceeds to update the state of...
Read more >
Spring Cloud Refresh event does not recognize removed ...
The issue stems from the class ConfigFileApplicationListener which on line 428, identifies the properties file as empty, so doesn't load the file into...
Read more >
Spring Cloud
Spring Cloud is released under the non-restrictive Apache 2.0 license. ... If a value cannot be decrypted it is removed from the property...
Read more >
Spring Cloud Azure developer guide | Microsoft Learn
Managed Identity support for Azure App Configuration, Event Hubs, ... These properties are optional and, if not specified, Spring Boot will ...
Read more >
Refresh Property Config at Runtime in Spring Cloud Config
A simple way to refresh configuration property is to use /refresh endpoint provided by spring boot actuator.But this is a manual process and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found