Spring IOC Container

Create Bean

Bean is an important component in spring framework.

Bean is an object in spring. A bean is an object which is instantiated, configured, wired and managed by spring IOC container.


One can create as many beans in the spring as required.

These beans are created after the container reads the configuration metadata provided either:

  • through xml file or
  • java based or
  • autowired mode.

In XML, bean can be created as shown below:

<bean class="com.javaradar.Employee. " id="emp"></bean>

This is the simplest way to create bean.

Here "class" refers to POJO java class for which you want spring container to create bean. And "id" is the identifier to recognize the bean and use it anywhere in the application. 

One of the common place where you will always use the id is while calling this bean.


Further  you can also provide other properties to the bean as shown below:

  • Scope
  • Properties
  • constructor-arg
  • autowiring 
  • destroy method
  • initialization method
  • lazy initialization

We will learn in depth about each of the properties in detail as we proceed further with this spring tutorial.

Moreover we will learn about other ways of creating bean like java based and autowired in respective sections.


Please Share this page
Views : 100
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!