• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring trying to understanding BeanPostProcessor

 
Ranch Hand
Posts: 53
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm newbie to Spring and i'm trying to understand the BeanPostProcessor - postProcessBeforeInitialization and postProcessAfterInitialization.

In short:

1) spring.xml

2) TrianglePostProcessor.java

3) DisplayBeanNamePostProcessor.java

4) DrawingApp.java

Now when i run the DrawingApp, i got the following messages:


In postProcessBeforeInitialization bean = org.tutorial.spring.Point#5f0101fb
In postProcessAfterInitialization bean = org.tutorial.spring.Point#5f0101fb
setPointA
In postProcessBeforeInitialization bean = triangle1
In postProcessAfterInitialization bean = triangle1

The `postProcessBeforeInitialization` as its word says should be before initialization but as you can see from the log, the setPointA is executed first and then the `postProcessBeforeInitialization` ..

Did I miss something?
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The properties of the bean are set right after the bean is created. The BeanPostProcessor.processBeforeInitialization is called before calling the init method of the bean
 
Kim Ming Yap
Ranch Hand
Posts: 53
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the BeanPostProcessor and InitializingBean is pretty much the same except that the former can be done for a large group of beans instead of per bean.
Also i noticed that BeanPostProcessor is done before the initializingBean if both of this exists.
But in theory they are the same.
am i right?
 
Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic