How to set Class value to spring bean property?

会有一股神秘感。 提交于 2019-12-01 02:27:53
skaffman

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>
laz

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!