We are experiencing a difference in behaviour when setting up a spring context in junit tests. Here is a simple project that shows the difference: https://github.com/mpiela/spring-ctx-bug. Usage:

mvn test

There are two tests in there: * SpringJavaConfigTest.java - uses @ContextConfiguration annotation and gives it a java @Configuration class * SpringXmlComponentScanTest.java - also uses a @ContextConfiguration but gives it a xml configuration file which in turn just does a component-scan.

The issue seems to be with an overriden @Bean method in a @Configuration class and omitting the bean name in the subclass.

Both of these tests pass on Spring 5.2.8. When we switched to Spring 5.2.9 the one with the xml configuration file starts failing.

I am not really sure if this is a bug that's been fixed in 5.2.8 and 5.2.9 is the expected behaviour or if it is the other way around.

Comment From: sbrannen

This may be related to the changes made in conjunction with the following issue:

  • 25263

In particular, see https://github.com/spring-projects/spring-framework/issues/25263#issuecomment-681836850.

Comment From: snicoll

Thanks for the sample.

SpringJavaConfigTest should never have worked. That base class who shadows the bean in the concrete class should not be created in the first place. Actually, we think that there's a case for throwing an exception for such an unusual use case.

From that perspective, the XML based test failing is the expected behavior. We'll tidy things up in 6.2.x to make things consistent.

Comment From: snicoll

When processing this, there is a sample demo for a similar, yet different use case that should be validated, see #28137.