Two Laptop Bag*
The moose likes Spring and the fly likes Spring trying to understanding BeanPostProcessor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring trying to understanding BeanPostProcessor" Watch "Spring trying to understanding BeanPostProcessor" New topic
Author

Spring trying to understanding BeanPostProcessor

Kim Ming Yap
Ranch Hand

Joined: Dec 17, 2008
Posts: 53

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?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2280
    
  28

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

Joined: Dec 17, 2008
Posts: 53

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring trying to understanding BeanPostProcessor
 
Similar Threads
Getting different output in a Spring project
Some help required for understanding spring lifecycle
Inheritance in Spring
Confused about bean's lifecycle method chain
example Code from Spring In Action