I'm new in spring f/w.
I've a doubt in <bean> tag. I'm setting the "init-method" & "destroy-method" to some method(say start() & stop()).
Here the problem is, I'm finding start() method getting executed but the stop() method not, means even if I'm reassigning a reference or explicitly assigning null to it, the stop() method doesn't get executed.
Any idea ???
Note, if you use XmlWebApplicationContext in a web environment, then close is called automatically when you undeploy or shutdown your web container.
coming to Jesus & Bill, I've made that bean's scope="prototype" & then assigning null to it & again also reassigning to it another new object, still the stop() method doesn't get executed........
coming to Mark, I'm not making any web application, it's simply an core java program & I'm creating appl context as,
ApplicationContext context = ClassPathXmlApplicationContext("hello.xml");
From the reference docs
In contrast to the other scopes, Spring does not manage the complete lifecycle of a prototype bean: the
container instantiates, configures, and otherwise assembles a prototype object, and hands it to the client,
with no further record of that prototype instance. Thus, although initialization lifecycle callback methods
are called on all objects regardless of scope, in the case of prototypes, configured destruction lifecycle
callbacks are not called. The client code must clean up prototype-scoped objects and release expensive
resources that the prototype bean(s) are holding. To get the Spring container to release resources held by
prototype-scoped beans, try using a custom bean post-processor, which holds a reference to beans that
need to be cleaned up.
In some respects, the Spring container's role in regard to a prototype-scoped bean is a replacement for the
Java new operator. All lifecycle management past that point must be handled by the client. (For details on
the lifecycle of a bean in the Spring container, see the section called “Lifecycle callbacks”.)