Results 1 to 4 of 4

Thread: When is setApplicationContext() from interface ApplicationContextAware

  1. #1
    Join Date
    Jan 2006
    Posts
    3

    Default When is setApplicationContext() from interface ApplicationContextAware

    Two implementations for configuring spring beans from XML application context files
    I.) new XmlBeanFactory( new FileSystemResource ("xml file path")

    II.) new FileSystemXmlApplicationContext (" xml file path")


    setApplicationContext() gets called in case II not I.

    WHY ???

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    XmlBeanFactory isn't an ApplicationContext, it's a BeanFactory hence ApplicationContextAware doesn't work with it. If you want to do the same thing with a BeanFactory, then implement BeanFactoryAware instead.
    http://www.springframework.org/docs/...anFactory.html
    http://www.springframework.org/docs/...onContext.html

    A class which implements the org.springframework.beans.factory.BeanFactoryAware interface is provided with a reference to the BeanFactory that created it, when it is created by that BeanFactory.
    http://www.springframework.org/docs/...anfactoryaware

    Event handling in the ApplicationContext is provided through the ApplicationEvent class and ApplicationListener interface. If a bean which implements the ApplicationListener interface is deployed into the context, every time an ApplicationEvent gets published to the ApplicationContext, that bean will be notified. Essentially, this is the standard Observer design pattern.
    http://www.springframework.org/docs/...onality-events

  3. #3
    Join Date
    Jan 2006
    Posts
    3

    Default

    Appreciate your suggestion. Thanks

    Quote Originally Posted by karldmoore View Post
    XmlBeanFactory isn't an ApplicationContext, it's a BeanFactory hence ApplicationContextAware doesn't work with it. If you want to do the same thing with a BeanFactory, then implement BeanFactoryAware instead.
    http://www.springframework.org/docs/...anFactory.html
    http://www.springframework.org/docs/...onContext.html


    http://www.springframework.org/docs/...anfactoryaware


    http://www.springframework.org/docs/...onality-events

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Not a problem. I can't actually remember the last time I used BeanFactory, usually I need the extra functionality provided by ApplicationContext. It's worth having quick read of the reference manual to make sure this isn't the case for you. Lots of people post with problems because of the differences between BeanFactory and ApplicationContext.
    http://www.springframework.org/docs/...nce/beans.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •