Register DynamicPropertyRegistry
as a singleton bean in a test's ApplicationContext
#32271
Labels
Milestone
Overview
DynamicPropertyRegistry
was introduced in conjunction with the@DynamicPropertySource
support in the TestContext framework. For such use cases, astatic
method within a test class must be annotated with@DynamicPropertySource
, and aDynamicPropertyRegistry
will be supplied as a method argument.However, it can also be useful to be able to register a "dynamic property" from within a test's
ApplicationContext
-- for example, in a@Bean
method in a@Configuration
class that is specific to testing scenarios.In light of that, we will register
DynamicPropertyRegistry
as a singleton bean in a test'sApplicationContext
. That will allowDynamicPropertyRegistry
to be autowired into a@Configuration
class or supplied to a@Bean
method as a method argument as shown in the following example.In order to address the
@DependsOn
concern raised in #32209, we are considering allowing@DynamicPropertySource
to be applied to@Bean
methods to indicate that the corresponding bean should be eagerly initialized within the test'sApplicationContext
.Related Issues
Environment
using properties of a bean #32209The text was updated successfully, but these errors were encountered: