Skip to content

@Conditional may prevent an import from taking effect [SPR-11788] #16410

@spring-projects-issues

Description

@spring-projects-issues

Andy Wilkinson opened SPR-11788 and commented

I've been investigating a problem with some auto-configuration in Boot. I've boiled it down into a simple test case (see attached) that hopefully illustrates the problem.

The problem is that if a configuration class is imported twice and one of those imports is excluded due to an unmatched condition then the ordering of the imports matters. If the unconditional import is processed first then the import is honoured and the imported configuration is processed. However, if the conditional import is processed first then the import is skipped.

I've dug around in the code a bit and the behaviour's due to a configuration class only having a single importedBy. Referring to the test case, this means that when ConditionalConfiguration is processed first it is BeanProvidingConfiguration's importedBy and TrackedConditionEvaluator skips it. Similarly, when UnconditionalConfiguration is processed first it is BeanProvidingConfiguration's importedBy and the configuration is processed.

I'm not sure if this is a bug or if it's by design, but it does seem rather brittle. The behaviour that I would like is for all of a configuration's importers to be considered and if any of them are unconditional or have a matching condition then the imported configuration should be processed.


Affects: 4.0.4

Attachments:

Issue Links:

0 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions