简体   繁体   English

如何销毁/清除使用Spring MVC中的applicationcontext.xml文件创建的对象?

[英]How to destroy / Clear an object created using applicationcontext.xml file in Spring MVC?

I am creating Web application using Spring 3.2.1... 我正在使用Spring 3.2.1创建Web应用程序...

I have injected number of beans from my ApplicationContext.xml file, Its gets initialized and works fine. 我已经从ApplicationContext.xml文件中注入了一定数量的bean,它被初始化并可以正常工作。

Now my Issue is, I want to destroy some of those(not all object) objects created using ApplicationContext.xml manually. 现在,我的问题是,我想销毁一些使用ApplicationContext.xml手动创建的对象(不是所有对象)。

Is it possible to destroy particular objects created using applicationcontext.xml file? 是否有可能破坏使用applicationcontext.xml文件创建的特定对象? If so please let me know the way to achieve it.. 如果是这样,请让我知道实现的方法。

Thanks in advance... 提前致谢...

The following snippet demonstrates how to remove a bean from the ApplicationContext. 以下代码段演示了如何从ApplicationContext中删除bean。

ConfigurableListableBeanFactory configurableListableBeanFactory = context
        .getBeanFactory();

BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) configurableListableBeanFactory;
// Removing the bean from container
beanDefinitionRegistry.removeBeanDefinition("demo");

Source 资源

To retrieve the ApplicationContext from a controller simply autowire the context. 要从控制器检索ApplicationContext ,只需自动关联上下文即可。

private @Autowired
ApplicationContext context;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM