Skip to content

Do not fail with a circular @Import error caused by an @ComponentScan [SPR-14517] #19086

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

Closed
spring-projects-issues opened this issue Jul 27, 2016 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 27, 2016

Jean-Pierre Bergamin opened SPR-14517 and commented

This ticket is a follow up on #17692:

We're facing a "Configuration problem: A circular @Import has been detected" error when upgrading from Spring Boot 1.3.1 to 1.3.5.

Our case is like:

A shared repository maven module contains:

@Configuration
@ComponentScan
MyRepositoryContextConfiguration {
}
@Configuration
@Import(MyRepositoryContextConfiguration.class)
MyRepositoryTestConfiguration {
}

A webapp using this shared repository (including it as a test-jar as well) has:

@Configuration
@Import(MyRepositoryTestConfiguration)
MyWebappTestConfiguration {
}

The component scan in the MyRepositoryContextConfiguration class picks up the MyRepositoryTestConfiguration again when running tests and leads to the following error:

Configuration problem: A circular @Import has been detected: Illegal attempt by @Configuration class 'MyRepositoryTestConfiguration' to import class 'MyRepositoryTestConfiguration' as 'MyRepositoryTestConfiguration' is already present in the current import stack [MyRepositoryTestConfiguration->MyWebappTestConfiguration]

A @ComponentScan should not trigger this error since it's not an explicit @Import definition.


Affects: 4.2.6

Reference URL: https://jira.spring.io/browse/SPR-13101?focusedCommentId=130875&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-130875

Issue Links:

Backported to: 4.2.8

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We provide isolated circular import detection for scanned classes now, since the initial registration did not come explicitly. In other words, we'll only fail if there's a user-declared circular import within the configuration class graph coming with a particular scanned class.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 27, 2016

Juergen Hoeller commented

The root cause here seems to be the change behind #18425... where the circular import change became reliable to begin with! Now it actually found previous imports in the entire stack and therefore uncovered its over-reaction on component-scanned imports for the first time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants