Hi,
I am registering Bean manually to the container this way:
Code:public class AppContextExtendingBean implements ApplicationContextAware{ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{ AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory(); addBean(beanFactory); } // create the object manually and then inject it into the spring context private void addBean(AutowireCapableBeanFactory beanFactory){ MyObject myObject=new MyObject("foo","phleem"); myObject.setBar("baz"); beanFactory.autowireBean(myObject); beanFactory.initializeBean(myObject, "bean2"); }
Now this bean is alive and working.
Now i am trying to destroy this bean manuall this way:
and I get this errorCode:AbstractBeanFactory factory = (AbstractBeanFactory) beanFactory; factory.destroyScopedBean("bean2");
Code:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'bean2' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractBeanFactory.destroyScopedBean(AbstractBeanFactory.java:977) at com.fixgw.sessions.SessionFactory.removeSessionByIntSessionId(SessionFactory.java:107) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.Trampoline.invoke(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) at javax.management.modelmbean.RequiredModelMBean.invokeMethod(Unknown Source) at javax.management.modelmbean.RequiredModelMBean.invoke(Unknown Source) at org.springframework.jmx.export.SpringModelMBean.invoke(SpringModelMBean.java:90) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source) at mx4j.tools.adaptor.http.InvokeOperationCommandProcessor.executeRequest(InvokeOperationCommandProcessor.java:164) at mx4j.tools.adaptor.http.HttpAdaptor$HttpClient.run(HttpAdaptor.java:980)
Why the container doesn't find bean with name bean2?
thanks,
ray.


Reply With Quote
).
