Reject bean names with factory prefix for Bean Overrides
Closes gh-33674
This commit is contained in:
@@ -56,6 +56,18 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
|
||||
@Test
|
||||
void beanNameWithFactoryBeanPrefixIsRejected() {
|
||||
AnnotationConfigApplicationContext context = createContext(FactoryBeanPrefixTestCase.class);
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean '&messageService' for field 'FactoryBeanPrefixTestCase.messageService': \
|
||||
a FactoryBean cannot be overridden. To override the bean created by the FactoryBean, remove the \
|
||||
'&' prefix.""");
|
||||
}
|
||||
|
||||
@Test
|
||||
void replaceBeanByNameWithMatchingBeanDefinition() {
|
||||
AnnotationConfigApplicationContext context = createContext(CaseByName.class);
|
||||
@@ -348,6 +360,18 @@ class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
interface MessageService {
|
||||
String getMessage();
|
||||
}
|
||||
|
||||
static class FactoryBeanPrefixTestCase {
|
||||
|
||||
@DummyBean(beanName = "&messageService")
|
||||
MessageService messageService;
|
||||
|
||||
}
|
||||
|
||||
static class CaseByName {
|
||||
|
||||
@DummyBean(beanName = "descriptionBean")
|
||||
@@ -464,11 +488,6 @@ class BeanOverrideBeanFactoryPostProcessorTests {
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface MessageService {
|
||||
String getMessage();
|
||||
}
|
||||
|
||||
static class MessageServiceTestCase {
|
||||
|
||||
@TestBean(name = "messageServiceBean")
|
||||
|
||||
Reference in New Issue
Block a user