BLOG.TIGABEATS.COM

A shrine where thoughts, ideas and random stuff is preserved

Spring 3.0 – BeanFactory vs ApplicationContext

ApplicationContext is much the same as a BeanFactory. Both load bean definitions, wire beans together, and dispense beans upon request.

But there are differences, ApplicationContext extends BeanFactory by providing additional features, see below the differences.

BeanFactory:

  • An Interface that implements Factory-Pattern
  • A bean factory “lazily loads” all beans, deferring bean creation until the getBean() method is called.

ApplicationContext:

  • Extends BeanFactory
  • An application context preloads all singleton beans upon context startup. By preloading singleton beans, you ensure that they will be ready to use when needed—your application won’t have to wait for them to be created.
  • Application contexts provide a means for resolving text messages, including support for internationalization (I18N) of those messages.
  • Application contexts provide a generic way to load file resources, such as images.
  • Application contexts can publish events to beans that are registered as listeners.

BeanFactory Implementations

  • XmlBeanFactory: A simple BeanFactory that loads a context definition file by way of a java.io.InputStream.

ApplicationContext Implementations

  • ClassPathXmlApplicationContext: it loads a context definition from an XML file located in the class path, treating context definition files as class path resources. e.g. ApplicationContext context = new ClassPathXmlApplicationContext(“foo.xml”);
  • FileSystemXmlApplicationContext: It loads a context definition from an XML file in the filesystem. e.g ApplicationContext context = new FileSystemXmlApplicationContext(“c:/foo.xml”);
  • XmlWebApplicationContext: It loads context definitions from an XML file contained within a web application.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>