revised lenient constructor resolution (follow-up to SPR-5816)

This commit is contained in:
Juergen Hoeller
2009-07-16 17:22:03 +00:00
parent 7eabd2da56
commit 8e2797153b
3 changed files with 26 additions and 9 deletions

View File

@@ -175,6 +175,10 @@
<constructor-arg index="1"><value>true</value></constructor-arg>
</bean>
<bean id="string" class="java.lang.String" autowire-candidate="false">
<constructor-arg><value type="java.lang.String">test</value></constructor-arg>
</bean>
<bean id="constructorArray" class="org.springframework.beans.factory.xml.XmlBeanFactoryTests$ConstructorArrayTestBean">
<constructor-arg type="int[]">
<array value-type="int">

View File

@@ -53,10 +53,10 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.MethodReplacer;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.UrlResource;
@@ -805,6 +805,7 @@ public final class XmlBeanFactoryTests {
fail("Must have thrown a FatalBeanException");
}
catch (FatalBeanException expected) {
// expected
}
DependenciesBean rod5 = (DependenciesBean) xbf.getBean("rod5");
@@ -1379,6 +1380,14 @@ public final class XmlBeanFactoryTests {
}
}
public @Test void testStringConstructor() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("string");
bd.setLenientConstructorResolution(false);
String str = (String) xbf.getBean("string");
assertEquals("test", str);
}
public @Test void testPrimitiveConstructorArray() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArray");