Pages

Sunday, September 9, 2012

spring el example

The spring Expression Language can be used to set properties to the beans. Note that we can do this also using xml method. Lets see an example.

@Component
public class Computer{

          @Value("#{motherBoard}")// motherBoard bean is referenced to this variable
          private MotherBoard motherBoard;// mother board is a dependency to the computer
}

@Component("motherBoard")//this bean can be taken using name motherBoard in getBean method
public class MotherBoard{

           @Value("asus")//asus is assigned as the property for the variable type in MotherBoard class.
           private String type;
}

This can be also done using Bean declaration in xml files also.

No comments:

Post a Comment