Introduce enforceOverride
flag in @TestBean
and @MockitoBean
#33613
Labels
Milestone
enforceOverride
flag in @TestBean
and @MockitoBean
#33613
Currently,
@MockitoBean
can be used to create or replace a bean definition, and@TestBean
can only be used to replace a bean definition.The reason is that the
@MockitoBean
support is hard coded to use theREPLACE_OR_CREATE_DEFINITION
strategy; whereas, the@TestBean
support is hard coded to use theREPLACE_DEFINITION
strategy.Instead of hard coding those strategies, we should introduce a new
enforceOverride
attribute in@TestBean
and@MockitoBean
that defaults totrue
but allows the user to decide if it's OK to create a bean for a nonexistent bean definition.TestBeanOverrideProcessor
andMockitoBeanOverrideProcessor
can then dynamically decide whether to use theREPLACE_DEFINITION
orREPLACE_OR_CREATE_DEFINITION
strategy based on theenforceOverride
flag.The text was updated successfully, but these errors were encountered: