It is possible to define an inner class annotated with @Configuration within the integration test class, however, from now on, the application context bootstrapped when we run tests inside the test class will only include the beans that defined within this configuration class. Even context component scan won't work unless it is enabled by that configuration class, therefore, none of those beans defined via stereotype annotations won't be available either.
The normal way to override any beans specific to the integration test class is to create an inner configuration class with @TestConfiguration annotation, which will have those bean definition overrides, or any specific configurations, special to that test class. Defining such a configuration class won't block normal application context configuration, so any configuration classes and components will be automatically discovered and loaded when the test is run.
If your test configuration class annotated with @TestConfiguration is defined as a top level class, then it won't be included in the application context automatically. Instead, it must be added explicitly either via @Import on top of a configuration class you just added specific for this test class, or via @ContextConfiguration annotation as a bean class.
If the configuration class with @Configuration annotation is defined within the BaseTest class, it will be discovered when test case within the SubTest class is run, but if there is an overriden bean definition within that configuration class it won't take effect.
For the bean definition override to work, you must create a config class within the SubTest, and annotate both config classes either with @Configuration or @TestConfiguration. However, be aware of that if you annotate them with @Configuration, then the above limitation will be in act. Therefore, it is better to go with the @TestConfiguration. You need to import the config class within BaseTest if both SubTest and BaseTest config classes are marked with @TestConfiguration.
@TestComponent annotation is a stereotype annotation which can be used to define beans that are only aimed for testing purposes. Therefore, putting that annotation on top the class alone wouldn't work. Instead, you need to explicitly tell Spring Test infra to load that bean class when the test is run.
One way to load is make use of @Import on top of the inner configuration class in order to specify that bean class should be explicitly listed to be loaded during test run. The other way is to specify that bean class via @ContextConfiguration annotation on top of the test class.
The whole benefit of using either @TestComponent or @TestConfiguration outside a test class is to make those test components and configurations available for other test classes as well. Otherwise, you just only make use of @TestConfiguration annotation within an inner configuration class.
The role of @Import annotation is to import any Spring ApplicationContext configuration class or component class into the ApplicationContext of the test being run.
By default, liveness and readiness probes only include livenessState and readinessState components which doesn't do anything useful. It might be useful to add other components into those probes so that status of the application should be queried better. You can achieve this by adding following properties into the application.properties file.