I've got two classes:
package package1;
@Component
public class MyClass1 {
...
package package2;
@Component
public class MyClass1 {
...
When I run failsafe (in maven) - I get the following error in spring (that I don't get in surefire):
test1(package3.MyIntegrationTest) Time elapsed: 6.737 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'myClass1' for bean class [packaging1.MyClass1] conflicts
with existing, non-compatible bean definition of same name and class [package2.MyClass1]
I get that to solve this I could get different Class names - or I could even specify
@Component(name="MyClass1a")
and
@Component(name="MyClass1b")
Or I could even set the package-scan
to only package1
.
(ie there are three ways to solve this that are obvious - but that's not my question).
That is NOT what I'm asking. (Ie this is not a duplicate).
Now to me - they should only clash in spring if they have the same package name. Surely Spring is smart enough to give them different shortened names if they have different packages?
My question is: Why would Spring 3 @Component names clash when they have different packages?