I created a CustomConfigServiceBootstrapConfiguration in order to access the Cloud Config service in the client side. I also need to access another bean in the CustomConfigServiceBootstrapConfiguration and I added also this bean to the spring.factories file.
I've noticed that when the actuator refresh is called all the beans that are in the spring.facatories org.springframework.cloud.bootstrap.BootstrapConfiguration are refreshed but they are not @refreshscoped beans. This is not the behaviour I was expecting. Any idea? I read that - /actuator/refresh to re-load the boot strap context - but it means that those beans are refreshed on every call to /actuator/refresh. Is there a way to make those beans behave like Singletons? so they wont be refreshed? Unless there is another way, instead of using the solution of writing a bean with an implementation of PropertySourceLocator and point to it in the spring.factories file, that doesn't involve the bootstrap enablement. I didn't find such way in your documentation
CustomConfigServiceBootstrapConfiguration class:
@Configuration
public class CustomConfigServiceBootstrapConfiguration {
@Autowired
SecretHandler secretHandler;
@Value("${auth.service.url}")
private String authServiceUrl;
@Bean
public ConfigServicePropertySourceLocator configServicePropertySourceLocator(ConfigClientProperties clientProperties, TokenManager tokenManager) {
ConfigServicePropertySourceLocator configServicePropertySourceLocator = new ConfigServicePropertySourceLocator(clientProperties);
configServicePropertySourceLocator.setRestTemplate(restTemplate(tokenManager));
return configServicePropertySourceLocator;
}
public RestTemplate restTemplate(TokenManager tokenManager) {
return new RestTemplateBuilder()
.interceptors(new CloudConfigInterceptor(tokenManager))
.build();
}
@Bean
JWTFeignTokenProvider jwtFeignTokenProvider(){
//TODO take the clientId & clientSecret from vault
String blabla = secretHandler.getSecret("blabla");
return new JWTFeignTokenProvider("springboot-no-ui-tests",
"hwcfEr", authServiceUrl);
}
@Bean
TokenManager tokenManager(JWTFeignTokenProvider jwtFeignTokenProvider){
return new TokenManager(jwtFeignTokenProvider);
}
}
spring.factories:
org.springframework.cloud.bootstrap.BootstrapConfiguration = com.test.VaultConfiguration,\
com.test.PropertiesSecretConfiguration,\
com.test.configuration.vault.VaultSecretsMapperConfiguration,\
com.test.bootstrap.configuration.RoleConfig,\
com.test..application.StageRoleConfig, \
com.test.application.ProductionRoleConfig, \
com.test.bootstrap.configuration.CustomConfigServiceBootstrapConfiguration
Comment From: spencergibb
please close this or the stack overflow question so we don't duplicate effort https://stackoverflow.com/questions/68989041/spring-beans-in-bootstrapconfiguration-in-spring-factories-refresh
Comment From: spring-cloud-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: avnerstr
What is the requested information you are looking for. I provided information above, what is missing?
Comment From: spencergibb
I'm not going to have this conversation in two places at once
Comment From: avnerstr
I closed the issue in Stackoverflow
Comment From: avnerstr
So it means that if I want to use beans in the Bootstrap and I want them to be singletons- because I don't want them to be refreshed. I have to create the singleton on my own? for example:
@Configuration
public class CustomConfigServiceBootstrapConfiguration {
private static ConfigServicePropertySourceLocator configServicePropertySourceLocator;
@Value("${auth.service.url}")
private String authServiceUrl;
@Bean
public ConfigServicePropertySourceLocator configServicePropertySourceLocator(ConfigClientProperties clientProperties) {
if(configServicePropertySourceLocator==null) {
configServicePropertySourceLocator = new ConfigServicePropertySourceLocator(clientProperties);
configServicePropertySourceLocator.setRestTemplate(restTemplate());
}
return configServicePropertySourceLocator;
}
private RestTemplate restTemplate() {
return new RestTemplateBuilder()
.interceptors(new CloudConfigInterceptor())
.build();
}
}
Comment From: avnerstr
any update? @spencergibb
Comment From: avnerstr
ping
Comment From: ryanjbaxter
Since the bootstrap context is reinitialized all the bootstrap beans would need to be recreated as well
Comment From: spring-cloud-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-cloud-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.