Whenever a bean instance is used for one particular property only, it can be declared as an inner bean. An inner bean declaration is enclosed in <property> or <constructor-arg> directly, without any id or name attribute set. In this way, the bean will be anonymous so that you can’tuse it anywhere else. In fact, even if you define an id or a name attribute for an inner bean, it will be ignored.
<bean id="sequenceGenerator" class="com.sequence.SequenceGenerator"> <property name="initial" value="100000" /> <property name="suffix" value="A" /> <property name="prefixGenerator"> <bean class="com.sequence.DatePrefixGenerator"> <property name="pattern" value="yyyyMMdd" /> </bean> </property> </bean>
An inner bean can also be declared in a constructor argument.
<bean id="sequenceGenerator" class="com.sequence.SequenceGenerator"> <constructor-arg> <bean class="com.sequence.DatePrefixGenerator"> <property name="pattern" value="yyyyMMdd" /> </bean> </constructor-arg> <property name="initial" value="100000" /> <property name="suffix" value="A" /> </bean>