Spring Bean Configuration Examples

  • XML file that can be developed either based on DTD rules or Schema rules. The XMLfile of certain software technology based applications either based on DTD or Schema rules supplied by that technology.
  • Contains Spring Bean configuration to make Spring Containers to recognize Spring.
  • Contains configuration for setter injections and constructor injections.
  • Any filename.xml can be taken as Spring Bean configuration file name and also contains     some misecllanious configurations related to Spring Beans.

Setting the Bean Properties :

public class ExampleBean {

      private String s;
      private int i;

      public void setStringProperty (String s) { this.s = s; }
      public void setIntegerProperty (int i) { this.i = i; }

  <bean id="exampleBean" class="ExampleBean">
       <property name="stringProperty"><value>Hi!</value></property>
       <property name="integerProperty"><value>1</value></property>

<property name="intProperty"><value>7</value></property>

<property name="doubleProperty"><value>0.25</value></property>

<property name="booleanProperty"><value>true</value></property>

<property name="colorProperty"><value>0,255,0</value></property>

java.awt.Color is initialized with RGB values.

Bean Constructor Configuration:

public class ExampleBean {
      private AnotherBean beanOne;
      private YetAnotherBean beanTwo;
      private int i;
      public ExampleBean (AnotherBean b1, YetAnotherBean b2, int i) {
          this.beanOne = b1;
          this.beanTwo = b2;
          this.i = i;

  <bean id="exampleBean" class="ExampleBean">
      <constructor-arg><ref bean="anotherExampleBean"/></constructor-arg>
      <constructor-arg><ref bean="yetAnotherBean"/></constructor-arg>

  <bean id="anotherExampleBean" class="AnotherBean"/>
  <bean id="yetAnotherBean" class="YetAnotherBean"/>