19

Possible Duplicate:
BeanFactory vs ApplicationContext

Simple word meaning of Application context and bean factory in spring framework.

Community
  • 1
  • 1
Sushant
  • 635
  • 2
  • 8
  • 19

1 Answers1

37

BeanFactory

The BeanFactory is the actual container which instantiates, configures, and manages a number of beans. These beans typically collaborate with one another, and thus have dependencies between themselves. These dependencies are reflected in the configuration data used by the BeanFactory (although some dependencies may not be visible as configuration data, but rather be a function of programmatic interactions between beans at runtime).

ApplicationContext

While the beans package provides basic functionality for managing and manipulating beans, often in a programmatic way, the context package adds ApplicationContext, which enhances BeanFactory functionality in a more framework-oriented style. Many users will use ApplicationContext in a completely declarative fashion, not even having to create it manually, but instead relying on support classes such as ContextLoader to automatically start an ApplicationContext as part of the normal startup process of a Java EE web-app. Of course, it is still possible to programmatically create an ApplicationContext.

The basis for the context package is the ApplicationContext interface, located in the org.springframework.context package. Deriving from the BeanFactory interface, it provides all the functionality of BeanFactory. To allow working in a more framework-oriented fashion, using layering and hierarchical contexts, the context package also provides the following:

  • MessageSource, providing access to messages in, i18n-style

  • Access to resources, such as URLs and files

  • Event propagation to beans implementing the ApplicationListener interface

  • Loading of multiple (hierarchical) contexts, allowing each to be focused on one particular layer, for example the web layer of an application

As the ApplicationContext includes all functionality of the BeanFactory, it is generally recommended that it be used over the BeanFactory, except for a few limited situations such as perhaps in an applet, where memory consumption might be critical, and a few extra kilobytes might make a difference. The following sections described functionality which ApplicationContext adds to basic BeanFactory capabilities.

http://static.springsource.org/spring/docs/1.2.x/reference/beans.html

nbro
  • 15,395
  • 32
  • 113
  • 196
Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70
  • 4
    Hi, I am reading a Spring 4 book. It mentions ApplicationContext. I know its an interface. But, what is this ApplicationContext really and what purpose does it serve (in plain english please) ? Why is the word application used ? Why not use SpringContext or UserContext ? – Erran Morad Jun 05 '14 at 23:26
  • @Borat Sagdiyev http://www.informit.com/articles/article.aspx?p=1245203&seqNum=3 i hope this will help you. – Faisal Naseer Aug 26 '15 at 11:43
  • this is by far the most simple and best explanation i have found through - https://dzone.com/articles/difference-between-beanfactory-and-applicationcont – Ashish Shetkar Feb 21 '19 at 14:08