Spring IoC container is heart of the spring framework. It is container to hold the spring objects and maintenance the spring objects lifecycle.

Spring provide two different type if containers.

BeanFactory Container

Here is how to create a bean and use it in java class.

<bean id = "..." class = "..." />
InputStream is = new FileInputStream("beans.xml");
BeanFactory factory = new XmlBeanFactory(is);
//Get the bean from XML
MyClass obj = (MyClass) factory.getBean("myClassObj");

BeanFactory Methods.

ApplicationContext container

This is more towards enterprise implementations, It has many extensible feature like AOP, Databases, logging, etc. It contains all the functionality of BeanFactory as well. It’s an interface “org.springframework.context.ApplicationContext”;

Common implementation are,

ApplicationContext appContext = new FileSystemXmlApplicationContext("beans.xml");
MyClass obj = (MyClass) context.getBean("myClassObj");