Spring Beans

In Spring, components are also called beansThe beans declared in the Spring IoC container are not required to be JavaBeans, they are POJOs.
POJO: (Plain Old Java Objects). - An ordinary Java object without any constraints, e.g. relating to some interface or class. It is used to distinguish lightweight Java components from heavyweight components in other complex component models (e.g., EJB components prior to version 3.1 of the EJB specification).


IoC Container (Inversion of Control)

Creates bean instances by reading their configurations. (Note: There are two implementations, the bean configuration files for these two types of IoC containers are identical. The application context provides more advanced features than the bean factory while keeping the basic features compatible. So we strongly recommend using the application context for every application unless the resources of this application are restricted, such as when running in an applet or a mobile device.)

Bean Factory

A factory design pattern implementation to create and dispense beans. As the bean factory knows about many objects within an application, it is able to create association between collaborating objects as they are instantiated. This removes the burden of configuration from the bean and the client.
BeanFactory  factory = new XmlBeanFactory(new FileInputStream("myBean.xml"));
myBean bean1 = (myBean)factory.getBean("myBean");

Application Context

While Bean Factory is used for simple applications, the Application Context is spring's more advanced container. Like 'BeanFactory' it can be used to load bean definitions, wire beans together and dispense beans upon request.
Also provides
1) a means for resolving text messages, including support for internationalization.
2) a generic way to load file resources.
3) events to beans that are registered as listeners.


For a large application with a lot of beans, you should separate them (the xml files containing them) in multiple configuration files according to their functionalities (e.g., controllers, DAO, and JMS). One useful division is by the architectural layer that a given context services.


Start by declaring a bean class, a bean.xml file (which includes instantiation parameters of a bean) and retrieving the bean object declared in the xml file:
Using application context: here.
Using bean factory: here.

Spring Recipes - A Problem Solution Approach by Mak, Long, and Rubio