Skip to content

ConflictingBeanDefinitionException on repeated index evaluation #24978

@ptahchiev

Description

@ptahchiev

This is a follow-up from the spring-boot gitter channel.
When upgrading the spring-boot bom from 2.2.5.RELEASE to 2.2.6.RELEASE I get this exception:

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'aBean' for bean class [com.example.demo.ABean] conflicts with existing, non-compatible bean definition of same name and class [com.example.demo.ABean]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:349) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:287) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]

The problem remains even when using 2.2.7.BUILD-SNAPSHOT.
Here's what I've discovered while debugging it:

This method returns false so an exception is raised.

  • It is important to have the spring-context-indexer dependency in your classpath. If you have it then the beans passed to isCompatible method will get getSource() return null.

  • it is also important to name the bean ABean. If I name it DemoBean then the exception does not happen - I think the component scan finds candidates sorted by beanName. So if ABean comes before DemoApplication then it will fail if I name it DemoBean then it will come after DemoApplication and it will not fail.

Here's a repository that reproduces the problem:
https://github.com/ptahchiev/conflicting-bean

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions