Announcement Announcement Module
Collapse
No announcement yet.
Bean destruction order Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean destruction order

    Will Spring destroy singletons in a specifc order upon exit? This is important in a scenario like this:

    - Bean A has a dependency on Bean B
    - Bean A's destroy-method refers to the instance of Bean B that it holds
    - I want to make sure that Bean B's destroy-method hasn't been called yet

    A realistic use case might be that Bean B is a database connection and Bean A wants to log to the database the fact that it is being destroyed.

    In other words, the order of destruction of beans should be the inverse of the order of creation. Is this the case?

    Thanks in advance.

  • #2
    Destruction should happen properly in relation to the dependencies that are expressed via properties and the explicit depends-on attribute. Basically it should be the reverse of the init/construct order.

    Just make sure that you are using Spring 1.1 or newer (preferably 1.1.1) as I know that Juergen fixed or tweaked this area a little while ago, in August if I remember...

    Comment


    • #3
      Originally posted by Colin Sampaleanu
      Just make sure that you are using Spring 1.1 or newer (preferably 1.1.1) as I know that Juergen fixed or tweaked this area a little while ago, in August if I remember...
      Just a remark:
      As I saw in JIRA, there still has been an issue that destroy-methods weren't invoked correctly for inner beans (SPR-390). The fix is targetet for 1.1.2

      Andreas

      Comment

      Working...
      X