Alex
Alex

Reputation: 5924

How to mock bean before ConfigDataLoader in SpringBootTest

Config file processing has been changed in Spring Boot 2.4. It allows to eliminate bootstrap configuration and use spring.config.import instead together with some specific locations like vault://…​. Internally it uses ConfigDataLocationResolver and ConfigDataLoader from the org.springframework.boot.context.config package.

We are using Spring Cloud Vault to load secrets during service startup

application.yml

spring.config.import: vault://...

It works perfectly and allows to eliminate all complexity related to bootstrap.yml but not sure how to create integration tests using SpringBootTest. For Vault we need to mock VaultTemplate bean that is instantiated in VaultConfigDataLoader

Currently we are using separate org.springframework.cloud.bootstrap.BootstrapConfiguration in META-INF/spring.factories to mock such beans but ideally we want to disable bootstrap completely and rely on a new config file lifecycle.

Are there any interceptors that allow to register mock bean before ConfigDataLoader without enabling bootstrap context?

Upvotes: 0

Views: 256

Answers (0)

Related Questions