verified choice of primary bean in case of implicit name match in a scanning plus factory method scenario (SPR-6065)
This commit is contained in:
parent
1b92a2fae1
commit
7b54746a50
|
|
@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.config.SimpleMapScope;
|
import org.springframework.beans.factory.config.SimpleMapScope;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.context.annotation4.DependencyBean;
|
||||||
import org.springframework.context.annotation4.FactoryMethodComponent;
|
import org.springframework.context.annotation4.FactoryMethodComponent;
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
@ -61,14 +62,14 @@ public class ClassPathFactoryBeanDefinitionScannerTests extends TestCase {
|
||||||
assertEquals("protectedInstance", tb.getName());
|
assertEquals("protectedInstance", tb.getName());
|
||||||
assertSame(tb, context.getBean("protectedInstance"));
|
assertSame(tb, context.getBean("protectedInstance"));
|
||||||
assertEquals("0", tb.getCountry());
|
assertEquals("0", tb.getCountry());
|
||||||
tb2 = (TestBean)context.getBean("protectedInstance"); //3
|
tb2 = context.getBean("protectedInstance", TestBean.class); //3
|
||||||
assertEquals("protectedInstance", tb2.getName());
|
assertEquals("protectedInstance", tb2.getName());
|
||||||
assertSame(tb2, tb);
|
assertSame(tb2, tb);
|
||||||
|
|
||||||
tb = (TestBean)context.getBean("privateInstance"); //4
|
tb = context.getBean("privateInstance", TestBean.class); //4
|
||||||
assertEquals("privateInstance", tb.getName());
|
assertEquals("privateInstance", tb.getName());
|
||||||
assertEquals(1, tb.getAge());
|
assertEquals(1, tb.getAge());
|
||||||
tb2 = (TestBean)context.getBean("privateInstance"); //4
|
tb2 = context.getBean("privateInstance", TestBean.class); //4
|
||||||
assertEquals(2, tb2.getAge());
|
assertEquals(2, tb2.getAge());
|
||||||
assertNotSame(tb2, tb);
|
assertNotSame(tb2, tb);
|
||||||
|
|
||||||
|
|
@ -78,6 +79,7 @@ public class ClassPathFactoryBeanDefinitionScannerTests extends TestCase {
|
||||||
|
|
||||||
QualifiedClientBean clientBean = context.getBean("clientBean", QualifiedClientBean.class);
|
QualifiedClientBean clientBean = context.getBean("clientBean", QualifiedClientBean.class);
|
||||||
assertSame(clientBean.testBean, context.getBean("publicInstance"));
|
assertSame(clientBean.testBean, context.getBean("publicInstance"));
|
||||||
|
assertSame(clientBean.dependencyBean, context.getBean("dependencyBean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -85,6 +87,9 @@ public class ClassPathFactoryBeanDefinitionScannerTests extends TestCase {
|
||||||
|
|
||||||
@Autowired @Qualifier("public")
|
@Autowired @Qualifier("public")
|
||||||
public TestBean testBean;
|
public TestBean testBean;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DependencyBean dependencyBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2009 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.context.annotation4;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class DependencyBean {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -69,4 +69,9 @@ public final class FactoryMethodComponent {
|
||||||
return new TestBean("requestScopedInstance", 3);
|
return new TestBean("requestScopedInstance", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DependencyBean secondInstance() {
|
||||||
|
return new DependencyBean();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue