org.springframework.beans.factory.BeanIsAbstractException Java Examples

The following examples show how to use org.springframework.beans.factory.BeanIsAbstractException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAbstractParentBeans() {
	DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
	parent.preInstantiateSingletons();
	assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));

	// abstract beans should not match
	Map<?, ?> tbs = parent.getBeansOfType(TestBean.class);
	assertEquals(2, tbs.size());
	assertTrue(tbs.containsKey("inheritedTestBeanPrototype"));
	assertTrue(tbs.containsKey("inheritedTestBeanSingleton"));

	// abstract bean should throw exception on creation attempt
	try {
		parent.getBean("inheritedTestBeanWithoutClass");
		fail("Should have thrown BeanIsAbstractException");
	}
	catch (BeanIsAbstractException ex) {
		// expected
	}

	// non-abstract bean should work, even if it serves as parent
	assertTrue(parent.getBean("inheritedTestBeanPrototype") instanceof TestBean);
}
 
Example #2
Source File: XmlBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAbstractParentBeans() {
	DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
	parent.preInstantiateSingletons();
	assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));

	// abstract beans should not match
	Map<?, ?> tbs = parent.getBeansOfType(TestBean.class);
	assertEquals(2, tbs.size());
	assertTrue(tbs.containsKey("inheritedTestBeanPrototype"));
	assertTrue(tbs.containsKey("inheritedTestBeanSingleton"));

	// abstract bean should throw exception on creation attempt
	try {
		parent.getBean("inheritedTestBeanWithoutClass");
		fail("Should have thrown BeanIsAbstractException");
	}
	catch (BeanIsAbstractException ex) {
		// expected
	}

	// non-abstract bean should work, even if it serves as parent
	assertTrue(parent.getBean("inheritedTestBeanPrototype") instanceof TestBean);
}
 
Example #3
Source File: AbstractBeanFactory.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * Check the given merged bean definition,
 * potentially throwing validation exceptions.
 * @param mbd the merged bean definition to check
 * @param beanName the name of the bean
 * @param args the arguments for bean creation, if any
 * @throws BeanDefinitionStoreException in case of validation failure
 */
protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, Object[] args)
		throws BeanDefinitionStoreException {

	// check if bean definition is not abstract
	if (mbd.isAbstract()) {
		throw new BeanIsAbstractException(beanName);
	}

	// Check validity of the usage of the args parameter. This can
	// only be used for prototypes constructed via a factory method.
	if (args != null && !mbd.isPrototype()) {
		throw new BeanDefinitionStoreException(
				"Can only specify arguments for the getBean method when referring to a prototype bean definition");
	}
}
 
Example #4
Source File: XmlBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAbstractParentBeans() {
	DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
	parent.preInstantiateSingletons();
	assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));

	// abstract beans should not match
	Map<?, ?> tbs = parent.getBeansOfType(TestBean.class);
	assertEquals(2, tbs.size());
	assertTrue(tbs.containsKey("inheritedTestBeanPrototype"));
	assertTrue(tbs.containsKey("inheritedTestBeanSingleton"));

	// abstract bean should throw exception on creation attempt
	try {
		parent.getBean("inheritedTestBeanWithoutClass");
		fail("Should have thrown BeanIsAbstractException");
	}
	catch (BeanIsAbstractException ex) {
		// expected
	}

	// non-abstract bean should work, even if it serves as parent
	assertTrue(parent.getBean("inheritedTestBeanPrototype") instanceof TestBean);
}
 
Example #5
Source File: BeanFactoryIntegrationTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest(name = "{0} profile")
@ValueSource(strings = {
        "",
        "web/desktop/chrome",
        "web/phone/iphone",
        "web/tablet/ipad",
        "web/desktop/chrome/mobile_emulation/phone",
        "web/desktop/chrome/mobile_emulation/tablet",
        "web/desktop/chrome/mobile_emulation/responsive"
})
void testBeanFactory(String profile)
{
    System.setProperty(CONFIGURATION_PROFILE, profile);
    System.setProperty(CONFIGURATION_ENVIRONMENTS, "integrationtest");
    BeanFactory.open();
    for (String beanName : BeanFactory.getBeanDefinitionNames())
    {
        try
        {
            BeanFactory.getBean(beanName).hashCode();
        }
        catch (@SuppressWarnings("unused") BeanIsAbstractException e)
        {
            // ignored
        }
    }
}
 
Example #6
Source File: TransactionalAnnotationTest.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void getNonAnnotatedTransactionalServices() {
    /* We only want to run getNonAnnotatedTransactionalSerivces once.
     * The tests actually just read the Maps that are generated here.
     */
    if (incorrectlyAnnotatedTransactionalServices != null) {
        return;
    }
    incorrectlyAnnotatedTransactionalServices = new HashMap<String, Class<? extends Object>>();
    nonAnnotatedTransactionalServices = new HashMap<String, String>();
    doubleAnnotatedTransactionalServices = new HashMap<String, String>();

    String[] beanNames = SpringContext.getBeanNames();
    for (String beanName : beanNames) {
        if ( beanName.endsWith( "-parentBean" ) ) {
            continue;
        }
        Object bean = null;
        try {
            bean = SpringContext.getBean(beanName);
        } catch ( BeanIsAbstractException ex ) {
            // do nothing, ignore
        } catch (Exception e) {
            LOG.warn("Caught exception while trying to obtain service: " + beanName);
            LOG.warn(e.getClass().getName() + " : " + e.getMessage(), e );
        }
        if (bean != null) {
            Class<? extends Object> beanClass = bean.getClass();
            if (beanClass.getName().matches(".*\\$Proxy.*")) {
                beanClass = AopUtils.getTargetClass(bean);
            }
            if (beanClass.getName().startsWith("org.kuali")
                    && !Modifier.isAbstract(beanClass.getModifiers())
                    && !beanClass.getName().endsWith("DaoOjb")
                    && !beanClass.getName().endsWith("DaoJdbc")
                    && !beanClass.getName().endsWith("Factory")
                    && !beanClass.getName().contains("Lookupable")
                    && !isClassAnnotated(beanName, beanClass)) {
                incorrectlyAnnotatedTransactionalServices.put(beanName, beanClass);
            }
        }
    }
    return;
}
 
Example #7
Source File: AbstractBeanFactory.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Check the given merged bean definition,
 * potentially throwing validation exceptions.
 * @param mbd the merged bean definition to check
 * @param beanName the name of the bean
 * @param args the arguments for bean creation, if any
 * @throws BeanDefinitionStoreException in case of validation failure
 */
protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object[] args)
		throws BeanDefinitionStoreException {

	if (mbd.isAbstract()) {
		throw new BeanIsAbstractException(beanName);
	}
}
 
Example #8
Source File: AbstractBeanFactory.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Check the given merged bean definition,
 * potentially throwing validation exceptions.
 * @param mbd the merged bean definition to check
 * @param beanName the name of the bean
 * @param args the arguments for bean creation, if any
 * @throws BeanDefinitionStoreException in case of validation failure
 */
protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object[] args)
		throws BeanDefinitionStoreException {

	if (mbd.isAbstract()) {
		throw new BeanIsAbstractException(beanName);
	}
}
 
Example #9
Source File: AbstractBeanFactory.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Check the given merged bean definition,
 * potentially throwing validation exceptions.
 * @param mbd the merged bean definition to check
 * @param beanName the name of the bean
 * @param args the arguments for bean creation, if any
 * @throws BeanDefinitionStoreException in case of validation failure
 */
protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, Object[] args)
		throws BeanDefinitionStoreException {

	if (mbd.isAbstract()) {
		throw new BeanIsAbstractException(beanName);
	}
}
 
Example #10
Source File: AbstractBeanFactory.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Check the given merged bean definition,
 * potentially throwing validation exceptions.
 * @param mbd the merged bean definition to check
 * @param beanName the name of the bean
 * @param args the arguments for bean creation, if any
 * @throws BeanDefinitionStoreException in case of validation failure
 */
protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, Object[] args)
		throws BeanDefinitionStoreException {

	if (mbd.isAbstract()) {
		throw new BeanIsAbstractException(beanName);
	}
}