Consistent bridge method handling in annotation post-processors
Issue: SPR-12490 Issue: SPR-12495
This commit is contained in:
@@ -50,6 +50,7 @@ import org.springframework.beans.factory.config.DestructionAwareBeanPostProcesso
|
||||
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
|
||||
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
import org.springframework.jndi.JndiLocatorDelegate;
|
||||
@@ -405,19 +406,21 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||
do {
|
||||
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
|
||||
for (Field field : targetClass.getDeclaredFields()) {
|
||||
PersistenceContext pc = field.getAnnotation(PersistenceContext.class);
|
||||
PersistenceUnit pu = field.getAnnotation(PersistenceUnit.class);
|
||||
if (pc != null || pu != null) {
|
||||
if (field.isAnnotationPresent(PersistenceContext.class) ||
|
||||
field.isAnnotationPresent(PersistenceUnit.class)) {
|
||||
if (Modifier.isStatic(field.getModifiers())) {
|
||||
throw new IllegalStateException("Persistence annotations are not supported on static fields");
|
||||
}
|
||||
currElements.add(new PersistenceElement(field, null));
|
||||
currElements.add(new PersistenceElement(field, field, null));
|
||||
}
|
||||
}
|
||||
for (Method method : targetClass.getDeclaredMethods()) {
|
||||
PersistenceContext pc = method.getAnnotation(PersistenceContext.class);
|
||||
PersistenceUnit pu = method.getAnnotation(PersistenceUnit.class);
|
||||
if ((pc != null || pu != null) && !method.isBridge() &&
|
||||
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||
continue;
|
||||
}
|
||||
if ((bridgedMethod.isAnnotationPresent(PersistenceContext.class) ||
|
||||
bridgedMethod.isAnnotationPresent(PersistenceUnit.class)) &&
|
||||
method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||
if (Modifier.isStatic(method.getModifiers())) {
|
||||
throw new IllegalStateException("Persistence annotations are not supported on static methods");
|
||||
@@ -425,8 +428,8 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||
if (method.getParameterTypes().length != 1) {
|
||||
throw new IllegalStateException("Persistence annotation requires a single-arg method: " + method);
|
||||
}
|
||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
||||
currElements.add(new PersistenceElement(method, pd));
|
||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||
currElements.add(new PersistenceElement(method, bridgedMethod, pd));
|
||||
}
|
||||
}
|
||||
elements.addAll(0, currElements);
|
||||
@@ -621,9 +624,8 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||
|
||||
private Properties properties;
|
||||
|
||||
public PersistenceElement(Member member, PropertyDescriptor pd) {
|
||||
public PersistenceElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
|
||||
super(member, pd);
|
||||
AnnotatedElement ae = (AnnotatedElement) member;
|
||||
PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
|
||||
PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
|
||||
Class<?> resourceType = EntityManager.class;
|
||||
|
||||
Reference in New Issue
Block a user