Announcement Announcement Module
Collapse
No announcement yet.
Life cycle of a bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Life cycle of a bean

    Hi,
    I am beginner with Spring Framework.I would like to know the life cycle of bean in the Spring container (how it is in both BeanFactory and ApplicationContext

  • #2
    Maybe this reference could be helpful.

    Regards,
    Andreas

    Comment


    • #3
      One thing that came to mind.
      Internally, the Spring Framework uses BeanPostProcessor implementations to process any marker interfaces it can find and call the appropriate methods.
      Doesn't this mean if you are using a BeanFacotry you'll have to declare this yourself as BeanPostProcessor's aren't automatically registered.

      Comment


      • #4
        No. At least when using DefaultListableBeanFactory things will be handled correctly. See the methods #initializeObject and #invokeInitMethods of DefaultListableBeanFactory.

        Regards,
        Andreas

        Comment


        • #5
          Originally posted by Andreas Senft View Post
          No. At least when using DefaultListableBeanFactory things will be handled correctly. See the methods #initializeObject and #invokeInitMethods of DefaultListableBeanFactory.
          Ok, I'll have a look at that later. It's something I'd not really thought of before, but just re-reading the section in the reference manual I wasn't sure if the callbacks would work with BeanFactory or not.

          The Spring Framework provides several marker interfaces to change the behavior of your bean in the container; they include InitializingBean and DisposableBean. Implementing these interfaces will result in the container calling afterPropertiesSet() for the former and destroy() for the latter to allow the bean to perform certain actions upon initialization and destruction.

          Internally, the Spring Framework uses BeanPostProcessor implementations to process any marker interfaces it can find and call the appropriate methods. If you need custom features or other lifecycle behavior Spring doesn't offer out-of-the-box, you can implement a BeanPostProcessor yourself.

          Comment


          • #6
            I tried it out, so I can confirm it to work. I have to agree, however, that from the reference manual things are not clear. In any case DefaultListableBeanFactory is just one implementation and not _the_ BeanFactory, after all. Maybe some kind of comparison table would be nice, which shows the supported features of BeanFactory and ApplicationContext side-by-side.

            Regards,
            Andreas

            Comment


            • #7
              It's funny you should say that. I had the same thoughts a while ago .
              http://opensource.atlassian.com/proj...rowse/SPR-3047

              Comment


              • #8
                Perfect
                So let's see what Rick comes up with. I am convinced it will make further explanations easier.

                Comment


                • #9
                  Indeed! It's come up so many times and has been the source of quite a few long running threads. Soon it's fixed the better.

                  Comment

                  Working...
                  X