Consistent bridge method handling in annotation post-processors
Issue: SPR-12490 Issue: SPR-12495
This commit is contained in:
parent
15d3b88037
commit
03d4e1bc22
|
|
@ -378,13 +378,28 @@ public abstract class BeanUtils {
|
||||||
* Find a JavaBeans {@code PropertyDescriptor} for the given method,
|
* Find a JavaBeans {@code PropertyDescriptor} for the given method,
|
||||||
* with the method either being the read method or the write method for
|
* with the method either being the read method or the write method for
|
||||||
* that bean property.
|
* that bean property.
|
||||||
* @param method the method to find a corresponding PropertyDescriptor for
|
* @param method the method to find a corresponding PropertyDescriptor for,
|
||||||
|
* introspecting its declaring class
|
||||||
* @return the corresponding PropertyDescriptor, or {@code null} if none
|
* @return the corresponding PropertyDescriptor, or {@code null} if none
|
||||||
* @throws BeansException if PropertyDescriptor lookup fails
|
* @throws BeansException if PropertyDescriptor lookup fails
|
||||||
*/
|
*/
|
||||||
public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException {
|
public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException {
|
||||||
|
return findPropertyForMethod(method, method.getDeclaringClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a JavaBeans {@code PropertyDescriptor} for the given method,
|
||||||
|
* with the method either being the read method or the write method for
|
||||||
|
* that bean property.
|
||||||
|
* @param method the method to find a corresponding PropertyDescriptor for
|
||||||
|
* @param clazz the (most specific) class to introspect for descriptors
|
||||||
|
* @return the corresponding PropertyDescriptor, or {@code null} if none
|
||||||
|
* @throws BeansException if PropertyDescriptor lookup fails
|
||||||
|
* @since 4.0.9
|
||||||
|
*/
|
||||||
|
public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException {
|
||||||
Assert.notNull(method, "Method must not be null");
|
Assert.notNull(method, "Method must not be null");
|
||||||
PropertyDescriptor[] pds = getPropertyDescriptors(method.getDeclaringClass());
|
PropertyDescriptor[] pds = getPropertyDescriptors(clazz);
|
||||||
for (PropertyDescriptor pd : pds) {
|
for (PropertyDescriptor pd : pds) {
|
||||||
if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) {
|
if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) {
|
||||||
return pd;
|
return pd;
|
||||||
|
|
@ -590,11 +605,11 @@ public abstract class BeanUtils {
|
||||||
actualEditable = editable;
|
actualEditable = editable;
|
||||||
}
|
}
|
||||||
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
|
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);
|
||||||
List<String> ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : null;
|
List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
|
||||||
|
|
||||||
for (PropertyDescriptor targetPd : targetPds) {
|
for (PropertyDescriptor targetPd : targetPds) {
|
||||||
Method writeMethod = targetPd.getWriteMethod();
|
Method writeMethod = targetPd.getWriteMethod();
|
||||||
if (writeMethod != null && (ignoreProperties == null || (!ignoreList.contains(targetPd.getName())))) {
|
if (writeMethod != null && (ignoreList == null || (!ignoreList.contains(targetPd.getName())))) {
|
||||||
PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
|
PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());
|
||||||
if (sourcePd != null) {
|
if (sourcePd != null) {
|
||||||
Method readMethod = sourcePd.getReadMethod();
|
Method readMethod = sourcePd.getReadMethod();
|
||||||
|
|
|
||||||
|
|
@ -397,14 +397,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Method method : targetClass.getDeclaredMethods()) {
|
for (Method method : targetClass.getDeclaredMethods()) {
|
||||||
AnnotationAttributes ann = null;
|
|
||||||
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
if (BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||||
ann = findAutowiredAnnotation(bridgedMethod);
|
continue;
|
||||||
}
|
|
||||||
else if (!method.isBridge()) {
|
|
||||||
ann = findAutowiredAnnotation(method);
|
|
||||||
}
|
}
|
||||||
|
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
|
||||||
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
|
|
@ -418,7 +415,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean required = determineRequiredStatus(ann);
|
boolean required = determineRequiredStatus(ann);
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
currElements.add(new AutowiredMethodElement(method, required, pd));
|
currElements.add(new AutowiredMethodElement(method, required, pd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1795,7 +1795,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ExtendedResourceInjectionBean<T> extends ResourceInjectionBean {
|
static class NonPublicResourceInjectionBean<T> extends ResourceInjectionBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public final ITestBean testBean3 = null;
|
public final ITestBean testBean3 = null;
|
||||||
|
|
@ -1808,7 +1808,7 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||||
|
|
||||||
public boolean baseInjected = false;
|
public boolean baseInjected = false;
|
||||||
|
|
||||||
public ExtendedResourceInjectionBean() {
|
public NonPublicResourceInjectionBean() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1851,12 +1851,11 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class TypedExtendedResourceInjectionBean extends ExtendedResourceInjectionBean<NestedTestBean> {
|
public static class TypedExtendedResourceInjectionBean extends NonPublicResourceInjectionBean<NestedTestBean> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class OverriddenExtendedResourceInjectionBean extends ExtendedResourceInjectionBean<NestedTestBean> {
|
public static class OverriddenExtendedResourceInjectionBean extends NonPublicResourceInjectionBean<NestedTestBean> {
|
||||||
|
|
||||||
public boolean subInjected = false;
|
public boolean subInjected = false;
|
||||||
|
|
||||||
|
|
@ -2251,7 +2250,6 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||||
|
|
||||||
private TestBean testBean3;
|
private TestBean testBean3;
|
||||||
|
|
||||||
|
|
||||||
@MyAutowired(optional = true)
|
@MyAutowired(optional = true)
|
||||||
protected void setTestBean3(TestBean testBean3) {
|
protected void setTestBean3(TestBean testBean3) {
|
||||||
this.testBean3 = testBean3;
|
this.testBean3 = testBean3;
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||||
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
|
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.core.BridgeMethodResolver;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.jndi.support.SimpleJndiBeanFactory;
|
import org.springframework.jndi.support.SimpleJndiBeanFactory;
|
||||||
|
|
@ -344,46 +345,50 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
throw new IllegalStateException("@WebServiceRef annotation is not supported on static fields");
|
throw new IllegalStateException("@WebServiceRef annotation is not supported on static fields");
|
||||||
}
|
}
|
||||||
currElements.add(new WebServiceRefElement(field, null));
|
currElements.add(new WebServiceRefElement(field, field, null));
|
||||||
}
|
}
|
||||||
else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
|
else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
throw new IllegalStateException("@EJB annotation is not supported on static fields");
|
throw new IllegalStateException("@EJB annotation is not supported on static fields");
|
||||||
}
|
}
|
||||||
currElements.add(new EjbRefElement(field, null));
|
currElements.add(new EjbRefElement(field, field, null));
|
||||||
}
|
}
|
||||||
else if (field.isAnnotationPresent(Resource.class)) {
|
else if (field.isAnnotationPresent(Resource.class)) {
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
throw new IllegalStateException("@Resource annotation is not supported on static fields");
|
throw new IllegalStateException("@Resource annotation is not supported on static fields");
|
||||||
}
|
}
|
||||||
if (!ignoredResourceTypes.contains(field.getType().getName())) {
|
if (!ignoredResourceTypes.contains(field.getType().getName())) {
|
||||||
currElements.add(new ResourceElement(field, null));
|
currElements.add(new ResourceElement(field, field, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Method method : targetClass.getDeclaredMethods()) {
|
for (Method method : targetClass.getDeclaredMethods()) {
|
||||||
if (!method.isBridge() && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
if (webServiceRefClass != null && method.isAnnotationPresent(webServiceRefClass)) {
|
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||||
|
if (webServiceRefClass != null && bridgedMethod.isAnnotationPresent(webServiceRefClass)) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
throw new IllegalStateException("@WebServiceRef annotation is not supported on static methods");
|
throw new IllegalStateException("@WebServiceRef annotation is not supported on static methods");
|
||||||
}
|
}
|
||||||
if (method.getParameterTypes().length != 1) {
|
if (method.getParameterTypes().length != 1) {
|
||||||
throw new IllegalStateException("@WebServiceRef annotation requires a single-arg method: " + method);
|
throw new IllegalStateException("@WebServiceRef annotation requires a single-arg method: " + method);
|
||||||
}
|
}
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
currElements.add(new WebServiceRefElement(method, pd));
|
currElements.add(new WebServiceRefElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
else if (ejbRefClass != null && method.isAnnotationPresent(ejbRefClass)) {
|
else if (ejbRefClass != null && bridgedMethod.isAnnotationPresent(ejbRefClass)) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
throw new IllegalStateException("@EJB annotation is not supported on static methods");
|
throw new IllegalStateException("@EJB annotation is not supported on static methods");
|
||||||
}
|
}
|
||||||
if (method.getParameterTypes().length != 1) {
|
if (method.getParameterTypes().length != 1) {
|
||||||
throw new IllegalStateException("@EJB annotation requires a single-arg method: " + method);
|
throw new IllegalStateException("@EJB annotation requires a single-arg method: " + method);
|
||||||
}
|
}
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
currElements.add(new EjbRefElement(method, pd));
|
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
else if (method.isAnnotationPresent(Resource.class)) {
|
else if (bridgedMethod.isAnnotationPresent(Resource.class)) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
throw new IllegalStateException("@Resource annotation is not supported on static methods");
|
throw new IllegalStateException("@Resource annotation is not supported on static methods");
|
||||||
}
|
}
|
||||||
|
|
@ -392,8 +397,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
throw new IllegalStateException("@Resource annotation requires a single-arg method: " + method);
|
throw new IllegalStateException("@Resource annotation requires a single-arg method: " + method);
|
||||||
}
|
}
|
||||||
if (!ignoredResourceTypes.contains(paramTypes[0].getName())) {
|
if (!ignoredResourceTypes.contains(paramTypes[0].getName())) {
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
currElements.add(new ResourceElement(method, pd));
|
currElements.add(new ResourceElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -519,9 +524,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
*/
|
*/
|
||||||
private class ResourceElement extends LookupElement {
|
private class ResourceElement extends LookupElement {
|
||||||
|
|
||||||
public ResourceElement(Member member, PropertyDescriptor pd) {
|
public ResourceElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
|
||||||
super(member, pd);
|
super(member, pd);
|
||||||
AnnotatedElement ae = (AnnotatedElement) member;
|
|
||||||
Resource resource = ae.getAnnotation(Resource.class);
|
Resource resource = ae.getAnnotation(Resource.class);
|
||||||
String resourceName = resource.name();
|
String resourceName = resource.name();
|
||||||
Class<?> resourceType = resource.type();
|
Class<?> resourceType = resource.type();
|
||||||
|
|
@ -564,9 +568,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
|
|
||||||
private final String wsdlLocation;
|
private final String wsdlLocation;
|
||||||
|
|
||||||
public WebServiceRefElement(Member member, PropertyDescriptor pd) {
|
public WebServiceRefElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
|
||||||
super(member, pd);
|
super(member, pd);
|
||||||
AnnotatedElement ae = (AnnotatedElement) member;
|
|
||||||
WebServiceRef resource = ae.getAnnotation(WebServiceRef.class);
|
WebServiceRef resource = ae.getAnnotation(WebServiceRef.class);
|
||||||
String resourceName = resource.name();
|
String resourceName = resource.name();
|
||||||
Class<?> resourceType = resource.type();
|
Class<?> resourceType = resource.type();
|
||||||
|
|
@ -612,7 +615,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
}
|
}
|
||||||
if (StringUtils.hasLength(this.wsdlLocation)) {
|
if (StringUtils.hasLength(this.wsdlLocation)) {
|
||||||
try {
|
try {
|
||||||
Constructor<?> ctor = this.lookupType.getConstructor(new Class<?>[] {URL.class, QName.class});
|
Constructor<?> ctor = this.lookupType.getConstructor(URL.class, QName.class);
|
||||||
WebServiceClient clientAnn = this.lookupType.getAnnotation(WebServiceClient.class);
|
WebServiceClient clientAnn = this.lookupType.getAnnotation(WebServiceClient.class);
|
||||||
if (clientAnn == null) {
|
if (clientAnn == null) {
|
||||||
throw new IllegalStateException("JAX-WS Service class [" + this.lookupType.getName() +
|
throw new IllegalStateException("JAX-WS Service class [" + this.lookupType.getName() +
|
||||||
|
|
@ -648,9 +651,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
|
||||||
|
|
||||||
private final String beanName;
|
private final String beanName;
|
||||||
|
|
||||||
public EjbRefElement(Member member, PropertyDescriptor pd) {
|
public EjbRefElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
|
||||||
super(member, pd);
|
super(member, pd);
|
||||||
AnnotatedElement ae = (AnnotatedElement) member;
|
|
||||||
EJB resource = ae.getAnnotation(EJB.class);
|
EJB resource = ae.getAnnotation(EJB.class);
|
||||||
String resourceBeanName = resource.beanName();
|
String resourceBeanName = resource.beanName();
|
||||||
String resourceName = resource.name();
|
String resourceName = resource.name();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -29,35 +29,38 @@ import static org.junit.Assert.*;
|
||||||
public class BridgeMethodAutowiringTests {
|
public class BridgeMethodAutowiringTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void SPR_8434() {
|
public void SPR8434() {
|
||||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||||
ctx.register(UserServiceImpl.class, Foo.class);
|
ctx.register(UserServiceImpl.class, Foo.class);
|
||||||
ctx.refresh();
|
ctx.refresh();
|
||||||
assertNotNull(ctx.getBean(UserServiceImpl.class).object);
|
assertNotNull(ctx.getBean(UserServiceImpl.class).object);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static abstract class GenericServiceImpl<D> {
|
||||||
|
|
||||||
abstract class GenericServiceImpl<D extends Object> {
|
public abstract void setObject(D object);
|
||||||
|
|
||||||
public abstract void setObject(D object);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class UserServiceImpl extends GenericServiceImpl<Foo> {
|
|
||||||
|
|
||||||
protected Foo object;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Inject
|
|
||||||
@Named("userObject")
|
|
||||||
public void setObject(Foo object) {
|
|
||||||
this.object = object;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class UserServiceImpl extends GenericServiceImpl<Foo> {
|
||||||
|
|
||||||
|
protected Foo object;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Inject
|
||||||
|
@Named("userObject")
|
||||||
|
public void setObject(Foo object) {
|
||||||
|
if (this.object != null) {
|
||||||
|
throw new IllegalStateException("Already called");
|
||||||
|
}
|
||||||
|
this.object = object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component("userObject")
|
||||||
|
public static class Foo {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component("userObject")
|
|
||||||
class Foo { }
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -566,20 +566,20 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ExtendedResourceInjectionBean extends ResourceInjectionBean {
|
static class NonPublicResourceInjectionBean<B> extends ResourceInjectionBean {
|
||||||
|
|
||||||
@Resource(name="testBean4", type=TestBean.class)
|
@Resource(name="testBean4", type=TestBean.class)
|
||||||
protected ITestBean testBean3;
|
protected ITestBean testBean3;
|
||||||
|
|
||||||
private ITestBean testBean4;
|
private B testBean4;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private INestedTestBean testBean5;
|
INestedTestBean testBean5;
|
||||||
|
|
||||||
private INestedTestBean testBean6;
|
INestedTestBean testBean6;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BeanFactory beanFactory;
|
BeanFactory beanFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Resource
|
@Resource
|
||||||
|
|
@ -588,12 +588,18 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resource(name="${tb}", type=ITestBean.class)
|
@Resource(name="${tb}", type=ITestBean.class)
|
||||||
private void setTestBean4(ITestBean testBean4) {
|
private void setTestBean4(B testBean4) {
|
||||||
|
if (this.testBean4 != null) {
|
||||||
|
throw new IllegalStateException("Already called");
|
||||||
|
}
|
||||||
this.testBean4 = testBean4;
|
this.testBean4 = testBean4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
public void setTestBean6(INestedTestBean testBean6) {
|
public void setTestBean6(INestedTestBean testBean6) {
|
||||||
|
if (this.testBean6 != null) {
|
||||||
|
throw new IllegalStateException("Already called");
|
||||||
|
}
|
||||||
this.testBean6 = testBean6;
|
this.testBean6 = testBean6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -601,7 +607,7 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||||
return testBean3;
|
return testBean3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITestBean getTestBean4() {
|
public B getTestBean4() {
|
||||||
return testBean4;
|
return testBean4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -630,6 +636,10 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class ExtendedResourceInjectionBean extends NonPublicResourceInjectionBean<ITestBean> {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class ExtendedEjbInjectionBean extends ResourceInjectionBean {
|
public static class ExtendedEjbInjectionBean extends ResourceInjectionBean {
|
||||||
|
|
||||||
@EJB(name="testBean4", beanInterface=TestBean.class)
|
@EJB(name="testBean4", beanInterface=TestBean.class)
|
||||||
|
|
@ -653,11 +663,17 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||||
|
|
||||||
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
|
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
|
||||||
private void setTestBean4(ITestBean testBean4) {
|
private void setTestBean4(ITestBean testBean4) {
|
||||||
|
if (this.testBean4 != null) {
|
||||||
|
throw new IllegalStateException("Already called");
|
||||||
|
}
|
||||||
this.testBean4 = testBean4;
|
this.testBean4 = testBean4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EJB
|
@EJB
|
||||||
public void setTestBean6(INestedTestBean testBean6) {
|
public void setTestBean6(INestedTestBean testBean6) {
|
||||||
|
if (this.testBean6 != null) {
|
||||||
|
throw new IllegalStateException("Already called");
|
||||||
|
}
|
||||||
this.testBean6 = testBean6;
|
this.testBean6 = testBean6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ import org.springframework.beans.factory.config.DestructionAwareBeanPostProcesso
|
||||||
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
|
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
|
||||||
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
|
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.core.BridgeMethodResolver;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.PriorityOrdered;
|
import org.springframework.core.PriorityOrdered;
|
||||||
import org.springframework.jndi.JndiLocatorDelegate;
|
import org.springframework.jndi.JndiLocatorDelegate;
|
||||||
|
|
@ -405,19 +406,21 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||||
do {
|
do {
|
||||||
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
|
LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
|
||||||
for (Field field : targetClass.getDeclaredFields()) {
|
for (Field field : targetClass.getDeclaredFields()) {
|
||||||
PersistenceContext pc = field.getAnnotation(PersistenceContext.class);
|
if (field.isAnnotationPresent(PersistenceContext.class) ||
|
||||||
PersistenceUnit pu = field.getAnnotation(PersistenceUnit.class);
|
field.isAnnotationPresent(PersistenceUnit.class)) {
|
||||||
if (pc != null || pu != null) {
|
|
||||||
if (Modifier.isStatic(field.getModifiers())) {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
throw new IllegalStateException("Persistence annotations are not supported on static fields");
|
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()) {
|
for (Method method : targetClass.getDeclaredMethods()) {
|
||||||
PersistenceContext pc = method.getAnnotation(PersistenceContext.class);
|
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
|
||||||
PersistenceUnit pu = method.getAnnotation(PersistenceUnit.class);
|
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
|
||||||
if ((pc != null || pu != null) && !method.isBridge() &&
|
continue;
|
||||||
|
}
|
||||||
|
if ((bridgedMethod.isAnnotationPresent(PersistenceContext.class) ||
|
||||||
|
bridgedMethod.isAnnotationPresent(PersistenceUnit.class)) &&
|
||||||
method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
|
||||||
if (Modifier.isStatic(method.getModifiers())) {
|
if (Modifier.isStatic(method.getModifiers())) {
|
||||||
throw new IllegalStateException("Persistence annotations are not supported on static methods");
|
throw new IllegalStateException("Persistence annotations are not supported on static methods");
|
||||||
|
|
@ -425,8 +428,8 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||||
if (method.getParameterTypes().length != 1) {
|
if (method.getParameterTypes().length != 1) {
|
||||||
throw new IllegalStateException("Persistence annotation requires a single-arg method: " + method);
|
throw new IllegalStateException("Persistence annotation requires a single-arg method: " + method);
|
||||||
}
|
}
|
||||||
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
|
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
|
||||||
currElements.add(new PersistenceElement(method, pd));
|
currElements.add(new PersistenceElement(method, bridgedMethod, pd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elements.addAll(0, currElements);
|
elements.addAll(0, currElements);
|
||||||
|
|
@ -621,9 +624,8 @@ public class PersistenceAnnotationBeanPostProcessor
|
||||||
|
|
||||||
private Properties properties;
|
private Properties properties;
|
||||||
|
|
||||||
public PersistenceElement(Member member, PropertyDescriptor pd) {
|
public PersistenceElement(Member member, AnnotatedElement ae, PropertyDescriptor pd) {
|
||||||
super(member, pd);
|
super(member, pd);
|
||||||
AnnotatedElement ae = (AnnotatedElement) member;
|
|
||||||
PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
|
PersistenceContext pc = ae.getAnnotation(PersistenceContext.class);
|
||||||
PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
|
PersistenceUnit pu = ae.getAnnotation(PersistenceUnit.class);
|
||||||
Class<?> resourceType = EntityManager.class;
|
Class<?> resourceType = EntityManager.class;
|
||||||
|
|
|
||||||
|
|
@ -774,7 +774,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public static class SpecificPublicPersistenceContextSetter extends DefaultPublicPersistenceContextSetter {
|
static class PublicPersistenceContextSetterOnNonPublicClass extends DefaultPublicPersistenceContextSetter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@PersistenceContext(unitName="unit2", type = PersistenceContextType.EXTENDED)
|
@PersistenceContext(unitName="unit2", type = PersistenceContextType.EXTENDED)
|
||||||
|
|
@ -784,6 +784,11 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public static class SpecificPublicPersistenceContextSetter extends PublicPersistenceContextSetterOnNonPublicClass {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class DefaultPrivatePersistenceUnitField {
|
public static class DefaultPrivatePersistenceUnitField {
|
||||||
|
|
||||||
@PersistenceUnit
|
@PersistenceUnit
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue