Describe the bug
When token in rotated in the vault, the property value is updated in the Spring Context Environment but the Refresh Event does not seem to be triggered. As the result, using @RefreshScope, @Value or @ConfigurationProperties does not work.
@Configuration
@RequiredArgsConstructor
public class CredentialConfiguration {
private final Environment environment;
@SneakyThrows
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
GoogleCredentials fromServiceKey() {
String privateKeyData = environment.getProperty("app.storage.credentials.private_key_data");
var decoded = Base64.getDecoder().decode(privateKeyData);
var stream = new ByteArrayInputStream(decoded);
return ServiceAccountCredentials.fromStream(stream);
}
However, if property is injected with @Value or @ConfigurationProperties, the old value assigned at the application startup is used even if @RefreshScope is added to the@Bean. And none of the beans annotated with @RefreshScope are recreated.
Expected behavior: when GET /v1/gcp-non-prod/static-account/svc-dev-rebatearc-gcs/key?prefix=app.storage.credentials. is invoked and a new value is received from the vault, the Refresh Event is published so any @Bean with @RefreshScope can be refreshed.
Describe the bug When token in rotated in the vault, the property value is updated in the Spring Context Environment but the Refresh Event does not seem to be triggered. As the result, using
@RefreshScope
,@Value
or@ConfigurationProperties
does not work.Sample Given vault config:
The following code is actually working:
However, if property is injected with
@Value
or@ConfigurationProperties
, the old value assigned at the application startup is used even if@RefreshScope
is added to the@Bean
. And none of the beans annotated with@RefreshScope
are recreated.Expected behavior: when
GET /v1/gcp-non-prod/static-account/svc-dev-rebatearc-gcs/key?prefix=app.storage.credentials.
is invoked and a new value is received from the vault, theRefresh Event
is published so any@Bean
with@RefreshScope
can be refreshed.