Annotation post-processors clear old InjectionMetadata registrations on refresh

Issue: SPR-12526
This commit is contained in:
Juergen Hoeller
2014-12-23 14:02:00 +01:00
parent dfdfc03ff3
commit 809ee0d350
6 changed files with 217 additions and 15 deletions

View File

@@ -330,7 +330,7 @@ public class PersistenceAnnotationBeanPostProcessor
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
if (beanType != null) {
InjectionMetadata metadata = findPersistenceMetadata(beanName, beanType);
InjectionMetadata metadata = findPersistenceMetadata(beanName, beanType, null);
metadata.checkConfigMembers(beanDefinition);
}
}
@@ -349,7 +349,7 @@ public class PersistenceAnnotationBeanPostProcessor
public PropertyValues postProcessPropertyValues(
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
InjectionMetadata metadata = findPersistenceMetadata(beanName, bean.getClass());
InjectionMetadata metadata = findPersistenceMetadata(beanName, bean.getClass(), pvs);
try {
metadata.inject(bean, beanName, pvs);
}
@@ -376,7 +376,7 @@ public class PersistenceAnnotationBeanPostProcessor
}
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz) {
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@@ -385,6 +385,9 @@ public class PersistenceAnnotationBeanPostProcessor
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
if (metadata != null) {
metadata.clear(pvs);
}
try {
metadata = buildPersistenceMetadata(clazz);
this.injectionMetadataCache.put(cacheKey, metadata);