如何设置类值为spring bean属性? [英] How to set Class value to spring bean property?
本文介绍了如何设置类值为spring bean属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,用Class值设置bean的属性的最好方法是什么?关于XML配置。对于这样的bean:
Hey, what is the best way to set a bean's property with Class value ? Regarding XML configuration. For a bean like this :
public class FilterJsonView extends MappingJacksonJsonView {
private Set<String> filteredAttributes;
private Class clazz;
public Set<String> getFilteredAttributes() {
return filteredAttributes;
}
public void setFilteredAttributes(Set<String> filteredAttributes) {
this.filteredAttributes = filteredAttributes;
}
public Class getClazz() {
return clazz;
}
public void setClazz(Class clazz) {
this.clazz = clazz;
}
}
推荐答案
注入类名,Spring会将它转换为 Class
对象,例如
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>
这篇关于如何设置类值为spring bean属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文