What is a bean in Spring ?

  • Typical java bean with a unique id
  • Typically defined in an XML file 
  • In spring there are basically two types
    • Singleton : One instance of the bean created and referenced each time it is requested
    • Prototype (non-singleton) : New bean created each time. Same as new ClassName()
  • Beans are normally created by Spring as late as possible
Example:

<bean id="exampleBean" class=”org.example.ExampleBean">

   <property name="beanOne"><ref bean="anotherExampleBean"/></property>

   <property name="beanTwo"><ref bean="yetAnotherBean"/></property>

   <property name="integerProperty"><value>1</value></property>

</bean>

 

Search:

Recent Posts