aspose file tools*
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
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring bean life cycle" Watch "Spring bean life cycle" New topic
Author

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
Bartender

Joined: Mar 07, 2007
Posts: 1282

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.

Marco
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring bean life cycle