spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

RefreshScope declared Beans are not refreshed

Open ct-dev-team opened this issue 5 months ago • 1 comments

Type: Bug

Component: Parameter Store

Describe the bug Hello Team, Thank you for your awesome work, I have stumbled upon an issue, I have declared a bean as @RefreshScope, this bean depends on another bean of @ConfigurationProperties, the @ConfigurationProperties does get refreshed however the @RefreshScope bean does not get refreshed.

Sample

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "prop")
public class PropConfigurationProperties {

    private String baseUrl;
}

@Slf4j
@Configuration
@RequiredArgsConstructor
public class WebConfig {

    @Bean
    @RefreshScope
    PropClient propClient(PropConfigurationProperties properties, WebClient.Builder builder) {
        System.out.println("Base URL: " + properties.getBaseUrl());
        WebClient build = builder.baseUrl(properties.getBaseUrl()).build();
        return HttpServiceProxyFactory.builder()
                .exchangeAdapter(WebClientAdapter.create(build))
                .build()
                .createClient(PropClient.class);
    }

    @EventListener
    public void handleContextRefresh(RefreshScopeRefreshedEvent event) {
        System.out.println(event);
        System.out.println("🔄 RefreshScopeRefreshedEvent triggered at: " + System.currentTimeMillis());
    }

    @EventListener
    public void handleEnvironmentChange(EnvironmentChangeEvent event) {
        System.out.println("🔄 EnvironmentChangeEvent triggered: " + event.getKeys());
    }
}

Both the @EventListener are triggered and I do see the output, however I do not see the output of System.out.println("Base URL: " + properties.getBaseUrl()); when the @EventListener are triggered. Please do let me know what am I doing wrong?

ct-dev-team avatar Jul 27 '25 05:07 ct-dev-team

Hey @ct-dev-team ,

could you please provide a sample repository so we can reproduce the issue?

Also, do you have actuator dependency in your poject?

MatejNedic avatar Jul 28 '25 09:07 MatejNedic