我依赖于Java EE 6应用程序中的XML处理内省,我已经工作了很长一段时间。到目前为止,它工作得很好。但是,我不得不重命名属性设置器名称。问题是,Introspector.getBeanInfo(Class<?>)
正在检测旧的和新的setter,即使在我
另外,我确保刷新了introspector的缓存:
public class BeanUtils {
public static Map<String, Class> propertyTypes(Class beanType) throws Exception {
HashMap<String, Class> propertyTypes = new HashMap<>();
for (PropertyDescriptor descriptor : Introspector.getBeanInfo(beanType).getPropertyDescriptors()) {
propertyTypes.put(descriptor.getName(), descriptor.getPropertyType());
}
return propertyTypes;
}
// Added this to flush the introspector
static {
Introspector.flushCaches();
}
}
这是我反省的课程:
public class AdhocUnavailableTimesRequestTag
{
public AdhocUnavailableTimeRequestTag[] getAdhocUnavailableTimes()
{
return adhocUnavailableTimes;
}
public void setUnavailableTimes(AdhocUnavailableTimeRequestTag[] adhocUnavailableTimes)
{
this.adhocUnavailableTimes = adhocUnavailableTimes;
}
private AdhocUnavailableTimeRequestTag[] adhocUnavailableTimes;
}
调用BeanUtils.propertyTypes(AdhocUnavailableTimesRequestTag.class)
会返回:
"adhocUnavailableTimes" => class [LAdhocUnavailableTimeRequestTag;
"class" => java.lang.Class"
"unavailableTimes" => class [LAdhocUnavailableTimeRequestTag;
什么可能导致内置检查器在不再存在时选择unavailableTimes
?我该如何解决?
答案 0 :(得分:1)
这将是方法setUnavailableTimes
的名称。您可以通过将方法重命名为setAdhocUnavailableTimes
来修复它。