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 id="enumValueTwo" class="com.companyname.ClassEnum" factory-method="valueOf">
		<constructor-arg value="SecondEnumValue" />

refer in bean :

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

reference :

Leave a Reply

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