• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Spring bean life cycle

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In realtime when do we play around with Bean life cycle to acheieve some particular goal.
Could you cite an example.
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!