Singular property | Simple property | Class Singer implements Performer { private String name; public Singer(String n) { this.name = n; } } | <bean id=”xyz” class=”com.Singer”> <constructor-arg value=”xyz”/> </bean> |
Class Singer implements Performer { private String name; public void setName(String n) { this.name = n; } } | <bean id=”xyz” class=”com.Singer”> <property name=”name” value=”xyz”/> </bean> | ||
Property referencing another bean | Class Drummer implements Performer { private Drum drum; public Drummer(Drum d) { this.drum = d; } } | <!-- Tabla implements Drum --> <bean id=”tabla” class=”com.Tabla”> </bean> <bean id=”xyz” class=”com.Drummer”> <constructor-arg ref=”tabla”/> </bean>
OR
<bean id=”xyz” class=”com.Drummer”> <constructor-arg> <!-- nested bean --> <bean class=”com.Tabla”> </constructor-arg> </bean>
| |
Class Drummer implements Performer { private Drum drum; public void setDrum(Drum d) { this.drum = d; } } | <!-- Tabla implements Drum --> <bean id=”tabla” class=”com.Tabla”> </bean> <bean id=”xyz” class=”com.Drummer”> <property name=”drum” ref=”tabla”/> </bean>
OR
<bean id=”xyz” class=”com.Drummer”> <property name=”drum”>
<!-- nested bean --> <bean class=”com.Tabla”> </property> </bean> | ||
Plural Property | Collections |
Class Drummer implements Performer {
// REFERENCE TYPE private Collection<Drum> drums; OR private List<Drum> drums; OR private Set<Drum> drums; public setDrums( Collection<Drum> drums) { this.drums = drums; }
// SIMPLE TYPE private Collection<String> names; public setNames(Coll... names) { this.names = names; } } | <bean id=”drum1” … /> <bean id=”drum2” … /> <bean id=”xyz” class=”com.Drummer”>
<!-- REFERENCE TYPE --> <property name=”drums”> <list or set> <ref bean=”drum1” /> <ref bean=”drum2” /> <bean class=”com.ADrum”/> <null /> </list or set> </property>
<!-- SIMPLE TYPE --> <property name=”names”> <list or set> <value>Name1</value> <value>Name2</value> <null /> </list or set> </property> </bean> |
Name value pairs |
Class Drummer implements Performer {
// Key and values are objects private Map<String, Drum> drums; public setDrums(Map... drums) { this.drums = drums; }
// key & values are strings private Properties notes; public setNotes(Properties note) { this.notes = note; } } | <bean id=”drum1” … /> <bean id=”drum2” … /> <bean id=”xyz” class=”com.Drummer”>
<property name=”drums”> <map> <entry key or key-ref=”drum1” value or value-ref=”drum1”/> <entry key=”drum2” value-ref=”drum2”/> </map> </property> <property name=”notes”> <prop key=”Note1”> lala </prop> <prop key=”Note21”> lolo </prop> </property> </bean> |
Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Tuesday, February 08, 2011
Simple Spring bean configuration
Labels:
Spring
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment