@ConfigurationProperties doesn't update if same values are injected elsewhere without annotation

331 Views Asked by At

I use @ConfigurationProperties with Zookeeper to update certain property values at runtime.

This relevant part of the code looks like this:

@Configuration
public class Config {

@Bean("limitedRepository")
public Repository limitedRepository(
        @Qualifier("repository") Repository repository,
        @Value("${some.property-one:1}") int one,
        @Value("${some.property-two:2}") int two) {
    return new LimitedRepository(repository, one, two);
}

@Bean("rateAdjuster")
@ConfigurationProperties(prefix = "some.property")
public RateAdjuster rateAdjuster(
        @Qualifier("limitedRepository") Repository limitedRepository,
        @Value("${some.property-one:1}") int one,
        @Value("${some.property-two:2}") int two,
        @Value("${some.property-three:3}") int three,
        @Value("${some.property-four:4}") int four
        ) {
    return new RateAdjuster(limitedRepository, one, two, three, four);
}
}

Bean limitedRepository uses values as rates, and rateAdjuster is bean with scheduled method that should adjust and set rates to limitedRepository bean based on certain criteria.

So my goal here would be:

  1. to set all properties on limitedRepository and rateAdjuster beans when the application runs
  2. when I want to update the properties, I want only properties on rateLimiter bean to update at runtime (rates on limitedRepository should only be updated by rateAdjuster).

And it almost works. It sets properties as it should, but something interesting happens.

  1. When I try to update properties three or four (they are set only in rateAdjuster bean) via Zookeeper, it works fine, the rateAdjuster is updated with those values
  2. When I try to update properties one or two (they are also set in limitedRepository bean) via Zookeeper, rateAdjuster doesn't update
  3. If I put @ConfigurationProperties(prefix = "some.property") on limitedRepository() method, then all properties can update at runtime, but this is not what I want

Could anyone help me to understand what is happening here and to hopefully find solution to this problem?

0

There are 0 best solutions below