lenientConstructorResolution flag applies to factory methods as well

This commit is contained in:
Juergen Hoeller
2009-07-27 14:09:42 +00:00
parent e85ad67fd0
commit 1eabe2b441
3 changed files with 35 additions and 1 deletions

View File

@@ -162,7 +162,7 @@
<constructor-arg value="NaN" type="double"/>
</bean>
<bean id="beanWithDoubleBoolean" class="org.springframework.beans.factory.xml.XmlBeanFactoryTests$DoubleBooleanConstructorBean" autowire="constructor" scope="prototype">
<bean id="beanWithDoubleBoolean" class="org.springframework.beans.factory.xml.XmlBeanFactoryTests$DoubleBooleanConstructorBean" autowire="constructor" scope="prototype" factory-method="create">
<constructor-arg type="java.lang.Boolean"><value>true</value></constructor-arg>
</bean>
@@ -175,6 +175,11 @@
<constructor-arg index="1"><value>true</value></constructor-arg>
</bean>
<bean id="beanWithDoubleBooleanNoTypeFactoryMethod" class="org.springframework.beans.factory.xml.XmlBeanFactoryTests$DoubleBooleanConstructorBean" scope="prototype" factory-method="create">
<constructor-arg index="0"><value>false</value></constructor-arg>
<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>

View File

@@ -1380,6 +1380,21 @@ public final class XmlBeanFactoryTests {
}
}
public @Test void testDoubleBooleanNoTypeFactoryMethod() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("beanWithDoubleBooleanNoTypeFactoryMethod");
bd.setLenientConstructorResolution(false);
try {
xbf.getBean("beanWithDoubleBooleanNoTypeFactoryMethod");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
ex.printStackTrace();
assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous"));
}
}
public @Test void testStringConstructor() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("string");
@@ -1632,6 +1647,14 @@ public final class XmlBeanFactoryTests {
public DoubleBooleanConstructorBean(String s1, String s2) {
throw new IllegalStateException("Don't pick this constructor");
}
public static DoubleBooleanConstructorBean create(Boolean b1, Boolean b2) {
return new DoubleBooleanConstructorBean(b1, b2);
}
public static DoubleBooleanConstructorBean create(String s1, String s2) {
return new DoubleBooleanConstructorBean(s1, s2);
}
}