How to set Class value to spring bean property? How to set Class value to spring bean property? spring spring

How to set Class value to spring bean property?


Just inject the class name, and Spring will convert it to a Class object for you, e.g.

<bean class="com.x.y.FilterJsonView">   <property name="clazz" value="com.x.y.SomeClass"/></bean>


Just supply the class name. Say you want clazz to be String.class:

<bean id="beanId" class="FilterJsonView">    <property name="clazz" value="java.lang.String"/></bean>

Spring has a PropertyEditorSupport implementation called ClassEditor that handles the conversions.