The coach object is created with Annotations and coach2 is created with XML configuration file. They both refering to the tennisCoach class.
In singleton scope beans refer to the same place in memory but in this situation memory place is different.
I have two questions.
Why Spring lets us create two objects?
Why it doesn't give an error about why an id is assigned to this object with annotation and we define the object again in XML or vice versa.
Does Spring create objects in prototype scope?
Coach coach = context.getBean("tennisCoach", Coach.class);
Coach coach2 = context.getBean("myCoach", Coach.class);
System.out.println(coach); //output: demo.TennisCoach@451001e5
System.out.println(coach2); //output: demo.TennisCoach@2b40ff9c
applicationContext.xml
<bean id="myCoach" class="demo.TennisCoach"></bean>
TennisCoach.java
@Component
public class TennisCoach implements Coach {...}
I know that one definition is enough for bean but I was just wondering about this situation.