|
|
|
|
@ -32,6 +32,7 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
|
|
|
|
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigUtils;
|
|
|
|
|
import org.springframework.context.support.GenericApplicationContext;
|
|
|
|
|
|
|
|
|
|
@ -39,77 +40,80 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Integration tests for handling JSR-303 {@link jakarta.inject.Qualifier} annotations.
|
|
|
|
|
* Integration tests for handling JSR-330 {@link jakarta.inject.Qualifier} and
|
|
|
|
|
* {@link javax.inject.Qualifier} annotations.
|
|
|
|
|
*
|
|
|
|
|
* @author Juergen Hoeller
|
|
|
|
|
* @author Sam Brannen
|
|
|
|
|
* @since 3.0
|
|
|
|
|
*/
|
|
|
|
|
class InjectAnnotationAutowireContextTests {
|
|
|
|
|
|
|
|
|
|
private static final String PERSON1 = "person1";
|
|
|
|
|
|
|
|
|
|
private static final String PERSON2 = "person2";
|
|
|
|
|
|
|
|
|
|
private static final String JUERGEN = "juergen";
|
|
|
|
|
|
|
|
|
|
private static final String MARK = "mark";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldWithSingleNonQualifiedCandidate() {
|
|
|
|
|
void autowiredFieldWithSingleNonQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() {
|
|
|
|
|
void autowiredMethodParameterWithSingleNonQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
|
|
|
|
|
void autowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("autowired"));
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("autowired"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldWithSingleQualifiedCandidate() {
|
|
|
|
|
void autowiredFieldWithSingleQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
|
|
|
|
|
person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
@ -118,15 +122,14 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredMethodParameterWithSingleQualifiedCandidate() {
|
|
|
|
|
void autowiredMethodParameterWithSingleQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
|
|
|
|
|
person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedMethodParameterTestBean bean =
|
|
|
|
|
@ -135,15 +138,14 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() {
|
|
|
|
|
void autowiredMethodParameterWithStaticallyQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(QualifiedPerson.class, cavs, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN,
|
|
|
|
|
context.registerBeanDefinition(PERSON1,
|
|
|
|
|
ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(person, JUERGEN), context, true).getBeanDefinition());
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedMethodParameterTestBean bean =
|
|
|
|
|
@ -152,18 +154,17 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() {
|
|
|
|
|
void autowiredMethodParameterWithStaticallyQualifiedCandidateAmongOthers() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(QualifiedPerson.class, cavs, null);
|
|
|
|
|
RootBeanDefinition person1 = new RootBeanDefinition(QualifiedPerson.class, cavs, null);
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedMethodParameterTestBean bean =
|
|
|
|
|
@ -172,15 +173,14 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredConstructorArgumentWithSingleQualifiedCandidate() {
|
|
|
|
|
void autowiredConstructorArgumentWithSingleQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
|
|
|
|
cavs.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
RootBeanDefinition person = new RootBeanDefinition(Person.class, cavs, null);
|
|
|
|
|
person.addQualifier(new AutowireCandidateQualifier(TestQualifier.class));
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedConstructorArgumentTestBean bean =
|
|
|
|
|
@ -189,7 +189,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldWithMultipleNonQualifiedCandidates() {
|
|
|
|
|
void autowiredFieldWithMultipleNonQualifiedCandidates() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -197,21 +197,20 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredMethodParameterWithMultipleNonQualifiedCandidates() {
|
|
|
|
|
void autowiredMethodParameterWithMultipleNonQualifiedCandidates() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -219,21 +218,20 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
|
|
|
|
|
void autowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -241,18 +239,17 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("autowired"));
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("autowired"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldResolvesQualifiedCandidate() {
|
|
|
|
|
void autowiredFieldResolvesQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -261,10 +258,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
|
|
|
|
|
@ -272,7 +268,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredMethodParameterResolvesQualifiedCandidate() {
|
|
|
|
|
void autowiredMethodParameterResolvesQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -281,10 +277,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedMethodParameterTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedMethodParameterTestBean bean =
|
|
|
|
|
@ -293,7 +288,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredConstructorArgumentResolvesQualifiedCandidate() {
|
|
|
|
|
void autowiredConstructorArgumentResolvesQualifiedCandidate() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -302,10 +297,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedConstructorArgumentTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedConstructorArgumentTestBean bean =
|
|
|
|
|
@ -313,8 +307,28 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-33345
|
|
|
|
|
void autowiredConstructorArgumentResolvesJakartaNamedCandidate() {
|
|
|
|
|
Class<JakartaNamedConstructorArgumentTestBean> testBeanClass = JakartaNamedConstructorArgumentTestBean.class;
|
|
|
|
|
AnnotationConfigApplicationContext context =
|
|
|
|
|
new AnnotationConfigApplicationContext(testBeanClass, JakartaCat.class, JakartaDog.class);
|
|
|
|
|
JakartaNamedConstructorArgumentTestBean bean = context.getBean(testBeanClass);
|
|
|
|
|
assertThat(bean.getAnimal1().getName()).isEqualTo("Jakarta Tiger");
|
|
|
|
|
assertThat(bean.getAnimal2().getName()).isEqualTo("Jakarta Fido");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-33345
|
|
|
|
|
void autowiredConstructorArgumentResolvesJavaxNamedCandidate() {
|
|
|
|
|
Class<JavaxNamedConstructorArgumentTestBean> testBeanClass = JavaxNamedConstructorArgumentTestBean.class;
|
|
|
|
|
AnnotationConfigApplicationContext context =
|
|
|
|
|
new AnnotationConfigApplicationContext(testBeanClass, JavaxCat.class, JavaxDog.class);
|
|
|
|
|
JavaxNamedConstructorArgumentTestBean bean = context.getBean(testBeanClass);
|
|
|
|
|
assertThat(bean.getAnimal1().getName()).isEqualTo("Javax Tiger");
|
|
|
|
|
assertThat(bean.getAnimal2().getName()).isEqualTo("Javax Fido");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
|
|
|
|
|
void autowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -324,10 +338,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedFieldWithDefaultValueTestBean bean =
|
|
|
|
|
@ -336,7 +349,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
|
|
|
|
|
void autowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -346,21 +359,20 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
|
|
|
|
|
void autowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -370,10 +382,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue(MARK);
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithDefaultValueTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedFieldWithDefaultValueTestBean bean =
|
|
|
|
|
@ -382,7 +393,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldResolvesWithMultipleQualifierValues() {
|
|
|
|
|
void autowiredFieldResolvesWithMultipleQualifierValues() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -396,10 +407,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
AutowireCandidateQualifier qualifier2 = new AutowireCandidateQualifier(TestQualifierWithMultipleAttributes.class);
|
|
|
|
|
qualifier2.setAttribute("number", 123);
|
|
|
|
|
person2.addQualifier(qualifier2);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedFieldWithMultipleAttributesTestBean bean =
|
|
|
|
|
@ -408,7 +418,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() {
|
|
|
|
|
void autowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -423,21 +433,20 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
qualifier2.setAttribute("number", 123);
|
|
|
|
|
qualifier2.setAttribute("value", "not the default");
|
|
|
|
|
person2.addQualifier(qualifier2);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
|
|
|
|
|
void autowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -452,10 +461,9 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
qualifier2.setAttribute("number", 123);
|
|
|
|
|
qualifier2.setAttribute("value", "default");
|
|
|
|
|
person2.addQualifier(qualifier2);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
context.refresh();
|
|
|
|
|
QualifiedFieldWithMultipleAttributesTestBean bean =
|
|
|
|
|
@ -464,7 +472,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() {
|
|
|
|
|
void autowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue(JUERGEN);
|
|
|
|
|
@ -479,38 +487,37 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
qualifier2.setAttribute("number", 123);
|
|
|
|
|
qualifier2.setAttribute("value", "default");
|
|
|
|
|
person2.addQualifier(qualifier2);
|
|
|
|
|
context.registerBeanDefinition(JUERGEN, person1);
|
|
|
|
|
context.registerBeanDefinition(MARK, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
context.registerBeanDefinition(PERSON1, person1);
|
|
|
|
|
context.registerBeanDefinition(PERSON2, person2);
|
|
|
|
|
context.registerBeanDefinition("autowired", new RootBeanDefinition(QualifiedFieldWithMultipleAttributesTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> {
|
|
|
|
|
assertThat(ex.getRootCause()).isInstanceOf(NoSuchBeanDefinitionException.class);
|
|
|
|
|
assertThat(ex.getBeanName()).isEqualTo("autowired");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
|
|
|
|
|
void autowiredConstructorArgumentDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
|
|
|
|
cavs1.addGenericArgumentValue("the real juergen");
|
|
|
|
|
RootBeanDefinition person1 = new RootBeanDefinition(Person.class, cavs1, null);
|
|
|
|
|
person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
|
|
|
|
|
person1.addQualifier(new AutowireCandidateQualifier(Qualifier.class, JUERGEN));
|
|
|
|
|
ConstructorArgumentValues cavs2 = new ConstructorArgumentValues();
|
|
|
|
|
cavs2.addGenericArgumentValue("juergen imposter");
|
|
|
|
|
RootBeanDefinition person2 = new RootBeanDefinition(Person.class, cavs2, null);
|
|
|
|
|
person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "juergen"));
|
|
|
|
|
person2.addQualifier(new AutowireCandidateQualifier(Qualifier.class, JUERGEN));
|
|
|
|
|
context.registerBeanDefinition("juergen1", person1);
|
|
|
|
|
context.registerBeanDefinition("juergen2", person2);
|
|
|
|
|
context.registerBeanDefinition("autowired",
|
|
|
|
|
new RootBeanDefinition(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean.class));
|
|
|
|
|
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(
|
|
|
|
|
context::refresh)
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("autowired"));
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
|
|
|
|
.isThrownBy(context::refresh)
|
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("autowired"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -543,7 +550,7 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
|
|
|
|
|
private static class QualifiedConstructorArgumentTestBean {
|
|
|
|
|
|
|
|
|
|
private Person person;
|
|
|
|
|
private final Person person;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
public QualifiedConstructorArgumentTestBean(@TestQualifier Person person) {
|
|
|
|
|
@ -557,6 +564,52 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class JakartaNamedConstructorArgumentTestBean {
|
|
|
|
|
|
|
|
|
|
private final Animal animal1;
|
|
|
|
|
private final Animal animal2;
|
|
|
|
|
|
|
|
|
|
@jakarta.inject.Inject
|
|
|
|
|
public JakartaNamedConstructorArgumentTestBean(@jakarta.inject.Named("Cat") Animal animal1,
|
|
|
|
|
@jakarta.inject.Named("Dog") Animal animal2) {
|
|
|
|
|
|
|
|
|
|
this.animal1 = animal1;
|
|
|
|
|
this.animal2 = animal2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Animal getAnimal1() {
|
|
|
|
|
return this.animal1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Animal getAnimal2() {
|
|
|
|
|
return this.animal2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class JavaxNamedConstructorArgumentTestBean {
|
|
|
|
|
|
|
|
|
|
private final Animal animal1;
|
|
|
|
|
private final Animal animal2;
|
|
|
|
|
|
|
|
|
|
@javax.inject.Inject
|
|
|
|
|
public JavaxNamedConstructorArgumentTestBean(@javax.inject.Named("Cat") Animal animal1,
|
|
|
|
|
@javax.inject.Named("Dog") Animal animal2) {
|
|
|
|
|
|
|
|
|
|
this.animal1 = animal1;
|
|
|
|
|
this.animal2 = animal2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Animal getAnimal1() {
|
|
|
|
|
return this.animal1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Animal getAnimal2() {
|
|
|
|
|
return this.animal2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class QualifiedFieldWithDefaultValueTestBean {
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
@ -593,13 +646,13 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean {
|
|
|
|
|
static class QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean {
|
|
|
|
|
|
|
|
|
|
private Person person;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
public QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean(
|
|
|
|
|
@Named("juergen") Person person) {
|
|
|
|
|
@Named(JUERGEN) Person person) {
|
|
|
|
|
this.person = person;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -636,6 +689,52 @@ class InjectAnnotationAutowireContextTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Animal {
|
|
|
|
|
|
|
|
|
|
String getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jakarta.inject.Named("Cat")
|
|
|
|
|
static class JakartaCat implements Animal {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return "Jakarta Tiger";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@javax.inject.Named("Cat")
|
|
|
|
|
static class JavaxCat implements Animal {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return "Javax Tiger";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jakarta.inject.Named("Dog")
|
|
|
|
|
static class JakartaDog implements Animal {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return "Jakarta Fido";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@javax.inject.Named("Dog")
|
|
|
|
|
static class JavaxDog implements Animal {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getName() {
|
|
|
|
|
return "Javax Fido";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Qualifier
|
|
|
|
|
|