0

In XML file in spring we have two bean with different id but same class. They have the same properties offcourse. Now I have InitializingBean interface and in afterPropertySet() I am just printing the value of properties.

Its printing the values two times for me?

Taky
  • 5,284
  • 1
  • 20
  • 29
user728907
  • 33
  • 6

2 Answers2

0

According Spring Documentation:

afterPropertySet()

Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

So the short answer on your question is: yes

Spring doesn't manipulate classes or object. Spring manipulates Bean Entity. It is the simplest object manipulated by Spring IOC. Bean has additional behaivior rules introduced by Spring.

If you create two beans for example with Singleton scope and not Lazy initializated Spring creates two instances of your class.

Community
  • 1
  • 1
Taky
  • 5,284
  • 1
  • 20
  • 29
0

Probably you are calling this Class also invoking a Test or by launching a Integration test like this . check the breakpoints , if you are using SpringRunner, try to mock the component