当前位置: 首页>>代码示例>>Java>>正文


Java DefaultListableBeanFactory.removeBeanDefinition方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.DefaultListableBeanFactory.removeBeanDefinition方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultListableBeanFactory.removeBeanDefinition方法的具体用法?Java DefaultListableBeanFactory.removeBeanDefinition怎么用?Java DefaultListableBeanFactory.removeBeanDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.support.DefaultListableBeanFactory的用法示例。


在下文中一共展示了DefaultListableBeanFactory.removeBeanDefinition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: register

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
/**
 * 动态注册bean
 * 
 * @author JohnGao
 */
public <T> void register(String beanName, Class<T> classType,
		Map<String, String> values) {
	ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) aContext;
	DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) configurableApplicationContext
			.getBeanFactory();
	if (defaultListableBeanFactory.isBeanNameInUse(beanName)) {
		defaultListableBeanFactory.removeBeanDefinition(beanName);
		logger.info("beanName-->" + beanName + "成功删除");
	}
	BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
			.genericBeanDefinition(classType);
	for (String key : values.keySet())
		beanDefinitionBuilder.addPropertyValue(key, values.get(key));
	defaultListableBeanFactory.registerBeanDefinition(beanName,
			beanDefinitionBuilder.getRawBeanDefinition());
	logger.info("beanName-->" + beanName + "成功注册");
}
 
开发者ID:gaoxianglong,项目名称:spring-zk-test,代码行数:23,代码来源:RegisterBean.java

示例2: processBeanDefinition

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Override
protected void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition bd, String beanClassName, String definitionName) throws FatalBeanException {
    if (beanFactory instanceof DefaultListableBeanFactory) {
        DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory;
        try {
            final WebScript webScript = AnnotationUtils.findAnnotation(Class.forName(beanClassName), WebScript.class);
            if (webScript != null) {
                String beanName = webScript.value();
                if (StringUtils.hasText(beanName)) {
                    final String webScriptName = "webscript." + beanName + "." + webScript.method().toString().toLowerCase();
                    factory.removeBeanDefinition(definitionName);
                    factory.registerBeanDefinition(webScriptName, bd);
                } else {
                    throw new FatalBeanException(String.format("%s is @WebScript annotated, but no value set.", beanClassName));
                }
            }
        } catch (ClassNotFoundException e) {
            logger.warn(String.format("ClassNotFoundException while searching for ChildOf annotation on bean name '%s' of type '%s'. This error is expected on Alfresco Community 4.2.c. for some classes in package 'org.alfresco.repo'", definitionName, beanClassName));
        }
    } else {
        logger.error(String.format("Unable to register '%s' as webscript because beanFactory is not instance of 'DefaultListableBeanFactory'", definitionName));
    }
}
 
开发者ID:andreacomo,项目名称:alfresco-annotations,代码行数:24,代码来源:WebScriptConfigurer.java

示例3: afterTestClass

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Override
public void afterTestClass(TestContext testContext) throws Exception {
    super.afterTestClass(testContext);
    /**
     * 重新注册被污染的bean
     */
    DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) testContext.getApplicationContext()
            .getAutowireCapableBeanFactory();
    for (Entry<String, Object> entry : testedObjects.entrySet()) {
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition(entry.getKey());
        beanFactory.removeBeanDefinition(entry.getKey());
        beanFactory.registerBeanDefinition(entry.getKey(), beanDefinition);
    }
}
 
开发者ID:warlock-china,项目名称:wisp,代码行数:15,代码来源:UnitTestDependencyInjectionTestExecutionListener.java

示例4: testBeanDefinitionRemoval

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testBeanDefinitionRemoval() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.setAllowBeanDefinitionOverriding(false);
	lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
	lbf.registerAlias("test", "test2");
	lbf.preInstantiateSingletons();
	lbf.removeBeanDefinition("test");
	lbf.removeAlias("test2");
	lbf.registerBeanDefinition("test", new RootBeanDefinition(NestedTestBean.class));
	lbf.registerAlias("test", "test2");
	assertTrue(lbf.getBean("test") instanceof NestedTestBean);
	assertTrue(lbf.getBean("test2") instanceof NestedTestBean);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:DefaultListableBeanFactoryTests.java


注:本文中的org.springframework.beans.factory.support.DefaultListableBeanFactory.removeBeanDefinition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。