Consistent bridge method handling in annotation post-processors

Issue: SPR-12490
Issue: SPR-12495
This commit is contained in:
Juergen Hoeller
2014-12-07 20:51:35 +01:00
parent 15d3b88037
commit 03d4e1bc22
8 changed files with 118 additions and 80 deletions

View File

@@ -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");
* you may not use this file except in compliance with the License.
@@ -29,35 +29,38 @@ import static org.junit.Assert.*;
public class BridgeMethodAutowiringTests {
@Test
public void SPR_8434() {
public void SPR8434() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(UserServiceImpl.class, Foo.class);
ctx.refresh();
assertNotNull(ctx.getBean(UserServiceImpl.class).object);
}
}
static abstract class GenericServiceImpl<D> {
abstract class GenericServiceImpl<D extends 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 abstract void setObject(D 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 { }

View File

@@ -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");
* 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)
protected ITestBean testBean3;
private ITestBean testBean4;
private B testBean4;
@Resource
private INestedTestBean testBean5;
INestedTestBean testBean5;
private INestedTestBean testBean6;
INestedTestBean testBean6;
@Resource
private BeanFactory beanFactory;
BeanFactory beanFactory;
@Override
@Resource
@@ -588,12 +588,18 @@ public class CommonAnnotationBeanPostProcessorTests {
}
@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;
}
@Resource
public void setTestBean6(INestedTestBean testBean6) {
if (this.testBean6 != null) {
throw new IllegalStateException("Already called");
}
this.testBean6 = testBean6;
}
@@ -601,7 +607,7 @@ public class CommonAnnotationBeanPostProcessorTests {
return testBean3;
}
public ITestBean getTestBean4() {
public B getTestBean4() {
return testBean4;
}
@@ -630,6 +636,10 @@ public class CommonAnnotationBeanPostProcessorTests {
}
public static class ExtendedResourceInjectionBean extends NonPublicResourceInjectionBean<ITestBean> {
}
public static class ExtendedEjbInjectionBean extends ResourceInjectionBean {
@EJB(name="testBean4", beanInterface=TestBean.class)
@@ -653,11 +663,17 @@ public class CommonAnnotationBeanPostProcessorTests {
@EJB(beanName="testBean3", beanInterface=ITestBean.class)
private void setTestBean4(ITestBean testBean4) {
if (this.testBean4 != null) {
throw new IllegalStateException("Already called");
}
this.testBean4 = testBean4;
}
@EJB
public void setTestBean6(INestedTestBean testBean6) {
if (this.testBean6 != null) {
throw new IllegalStateException("Already called");
}
this.testBean6 = testBean6;
}