List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition setLenientConstructorResolution
public void setLenientConstructorResolution(boolean lenientConstructorResolution)
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
@Test public void testNonLenientDependencyMatching() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBean"); bd.setLenientConstructorResolution(false); try {//from w ww . j a v a2s.co m xbf.getBean("lenientDependencyTestBean"); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { // expected ex.printStackTrace(); assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous")); } }
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
@Test public void testNonLenientDependencyMatchingFactoryMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf .getBeanDefinition("lenientDependencyTestBeanFactoryMethod"); bd.setLenientConstructorResolution(false); try {/*from w ww .ja v a 2 s .c o m*/ xbf.getBean("lenientDependencyTestBeanFactoryMethod"); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { // expected ex.printStackTrace(); assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous")); } }
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
@Test public void testJavaLangStringConstructor() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("string"); bd.setLenientConstructorResolution(false); String str = (String) xbf.getBean("string"); assertEquals("test", str); }
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
@Test public void testCustomStringConstructor() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("stringConstructor"); bd.setLenientConstructorResolution(false); StringConstructorTestBean tb = (StringConstructorTestBean) xbf.getBean("stringConstructor"); assertEquals("test", tb.name); }
From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java
@Test public void testStringConstructorArrayNoTypeNonLenient() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("constructorArrayNoType"); bd.setLenientConstructorResolution(false); ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType"); assertTrue(bean.array instanceof String[]); assertEquals(0, ((String[]) bean.array).length); }