• Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring bean life cycle  RSS feed

 
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
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • 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 Java Spring
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!