How to inject enum value as a property in beans declarations in spring..?

I come across requirement to insert enum value as property in bean ( This is while working with Hybris enums ).

I tried myself and then googled( ref in references ) and i found the solution.

refer each value of enum :

	<bean id="enumValueOne" class="com.companyname.ClassEnum" factory-method="valueOf">
		<constructor-arg value="FirstEnumValue" />
	</bean>
	<bean id="enumValueTwo" class="com.companyname.ClassEnum" factory-method="valueOf">
		<constructor-arg value="SecondEnumValue" />
	</bean>

refer in bean :

<code>
<bean id="sampleBean" class="com.companyname.samplebean" parent="ParentBean">
		<property name="propertyOne">
			<list>
				<ref bean="enumValueOne" />
				<ref bean="enumValueTwo" />
			</list>
		</property>
	</bean>
</code>

reference :
http://stackoverflow.com/questions/14072314/inject-the-value-of-an-enum-into-a-property-using-spring

Leave a Reply

Your email address will not be published. Required fields are marked *