Hello,
I have a weird question, which is the opposite of pretty much all the questions I saw on here :P
Basically, I have an interface
with a subinterfaceCode:public interface Manager { Object create(); }
The main interface is implemented 3 times by different classes in this wayCode:public interface SubManager { Object delete(); }
Code:public class MainManager implements SubManager { public Object create() { ... } public Object deleted() { ... } }Code:public class SecondManager implements Manager { public Object create() { ... } }All of the config is defined in XML (no annotations yet anywhere in those classes)Code:public class ThirdManager implements Manager { public Object create() { ... } }
Code:<bean id="mainManager" class = "com.manager.impl.MainManager"> <bean id="secondManager" class = "com.manager.impl.SecondManager"> <bean id="thirdManager" class = "com.manager.impl.ThirdManager">
Then I created a new class
And ... everything works fine, it gets the mainManager like it's supposed to, butCode:public DoSomething { @Autowired private Manager manager; ... }
My question is : Why the hell does this work?
Everywhere I've read, Spring says that if there is more than 1 bean defined, there will be an exception, every search I do on Google tells me the same
Why is spring taking my first bean into account and ignoring the rest?
PS: There is no primary bean defined in any case, not in XML nor in Spring annotations
PS 2 : I've defined a second bean with @Resource(name="secondManager") to see if, maybe, it didn't load my beans correctly, but that bean works too, so it turns out all my managers are loaded :|
PS 3 : I'm using Spring v3.2
I know the fix to this (@Resource), but the fact that it doesn't follow the behavior it's supposed to scares me a lil bit


Reply With Quote