This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Spring and the fly likes Spring bean life cycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring bean life cycle" Watch "Spring bean life cycle" New topic

Spring bean life cycle

vijay jacob
Ranch Hand

Joined: Jul 02, 2013
Posts: 57

In realtime when do we play around with Bean life cycle to acheieve some particular goal.
Could you cite an example.
Marco Ehrentreich
best scout

Joined: Mar 07, 2007
Posts: 1294

A typical example are resources like some kind of database handler for example which needs some initialization steps and/or logic to clean up resources when it's no longer needed. In this case lifecycle callback methods called by the framework (IoC container) are a convenient way to initialize and destroy resources exactly once at the right time without manually having to call a init() or cleanup() method.

Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 607

The use case would also vary by framework.
As an example in the Spring Batch Space - framework methods like @AfterStep, @BeforeStep are heavily used.

Internal bean life cycle are also used internally by the Spring Framework - e.g the PropertyPlaceholderConfigurer would need to implement BeanFactoryPostProcessor to inject properties before other beans are created.

Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
I agree. Here's the link:
subject: Spring bean life cycle
It's not a secret anymore!