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;
}
}
Just inject the class name, and Spring will convert it to a
Class
object for you, e.g.Just supply the class name. Say you want
clazz
to beString.class
:Spring has a
PropertyEditorSupport
implementation calledClassEditor
that handles the conversions.