Reputation: 451
Im using Spring boot 2.6.6, I need to customize SpringApplication for the field bootstrapRegistryInitializers to use custom HttpComponentsClientHttpRequestFactory for AbstractVaultConfiguration class.
public static void main(String[] args) {
SpringApplication app = new SpringApplication(StandardsMicroserviceApplication3.class);
Long ttl = null; // get here the value of property "vault.ttl" which should be provided by spring mechanism (@Value, Environment class...)
HttpClientBuilder builder = HttpClientBuilder.create().setConnectionTimeToLive(ttl, TimeUnit.SECONDS);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(builder.build());
app.addBootstrapRegistryInitializer(registry -> {
registry.register(AbstractVaultConfiguration.ClientFactoryWrapper.class,
BootstrapRegistry.InstanceSupplier.of(new AbstractVaultConfiguration.ClientFactoryWrapper(requestFactory)));
});
app.run(args);
}
However i need to get value from spring property (for example vault.ttl) to configure the HttpclientBuilder with right parameters.
Is it possible to get spring property value before running the Spring application (app.run(args)) ?
Is it possible to configure the SpringApplication's BoostraRegistryInitializers field after running the application and apply it the spring context to be effective ?
Upvotes: 1
Views: 408