Spring auto-configuration can be tricky when it comes to conditional based bean creation. The best way to ensure the proper application context is through meticulous testing.
Spring Boot 2.X provides some test helpers for easily configuring an ApplicationContext to simulate auto-configuration test scenarios.
Utility design to run an ApplicationContext and provide AssertJ style assertions. The test is best used as a field of a test class,
Let’s try this with a use case,
Feature Toggling
Let’s assume the application consists of multiple features and these features are toggled ( bean creation ) by environment configuration-based conditions,
Feature Definition
All the features of the application are defined as an enum and the enum contains a code and the application configuration itself. For simplicity let’s consider an app with 3 features.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters