From aa167e2c04575b7aaf48058f7c17147cc352178f Mon Sep 17 00:00:00 2001 From: Tomasz Wysocki Date: Wed, 13 May 2015 12:24:28 +0200 Subject: [PATCH] Change property reflection mechanisms from java.beans.Introspector into spring specific BeanUtils. The purpose is to: 1. cache the introspection results 2. enable BeanInfoFactory support to custom bean reflection strategies (fluent setters, default methods with getters/setters etc.) --- .../data/mapping/context/AbstractMappingContext.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index d64ff32000..6e2608f48d 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -15,9 +15,6 @@ */ package org.springframework.data.mapping.context; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -34,6 +31,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; @@ -281,10 +280,10 @@ protected E addPersistentEntity(TypeInformation typeInformation) { // Eagerly cache the entity as we might have to find it during recursive lookups. persistentEntities.put(typeInformation, entity); - BeanInfo info = Introspector.getBeanInfo(type); + PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(type); final Map descriptors = new HashMap(); - for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) { + for (PropertyDescriptor descriptor : pds) { descriptors.put(descriptor.getName(), descriptor); } @@ -308,7 +307,7 @@ protected E addPersistentEntity(TypeInformation typeInformation) { return entity; - } catch (IntrospectionException e) { + } catch (BeansException e) { throw new MappingException(e.getMessage(), e); } finally { write.unlock();