本文整理汇总了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 + "成功注册");
}
示例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));
}
}
示例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);
}
}
示例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);
}