-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Name of scanned @Configuration class affects @Import to work or fail #24643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, In such case, The problem is that at I think it is not possible to tune such behavior (without big refactoring), you should probably redesign your configuration |
Thank you for looking into this! I perfectly agree, that the configuration class is loaded twice. But this is normal and happens all the time: All And for that case “a configuration class is found by the First, I might be wrong, but to me it looks like the order of the entries in Now the other case: While processing However now And here we have the problem IMHO: With this removal and re-adding the order in I understand the comment here, that “explicit bean definition should replace an import” is intended, however this To solve this, I think adding
before this removal (in line 240) should be enough, while This does not sound like a major change to me? |
Hi, Thanks for the detailed response :) Let me double check it |
The behavior is inconsistent indeed, I will prepare the PR soon |
As I mentioned, it is not that simple unfortunately and I'm afraid of possible side effects. Anyway, lets try to fix it |
What side effects do you have in mind? |
Our projects rely heavily on bean overriding (yes, we know, disabled now by default for good reasons, but still useful at times and a different story).
We now traced down a phenomenon that the name of a
@Configuration
class found by the@ComponentScan
seem to affect, whether overriding with@Import
(or sub-classing) works properly. This is though theConfigurationClassParser
already does a lot of handling on this case, e. g. inprocessConfigurationClass
.Please find a test case in https://github.com/abenneke/sandbox/tree/master/spring-import-order:
It contains four
@Configuration
classes: Two for a "foo" bean (FooConfigurationA+B
) and two for a "bar" bean (BarConfigurationA+B
). However, the@Import
order is different between both configurations:FooConfigurationB
is importingFooConfigurationA
whileBarConfigurationA
is importingBarConfigurationB
.In the test we now see that overriding works as expected for "foo", but fails for "bar"!?
Just to make sure we did not miss anything, we added the very same test using standard Spring methods and again using Spring Boot - but it does not make any difference here.
The text was updated successfully, but these errors were encountered: