It seems that it will not be null.
I have an interface Coach, and class that implements it TrackCoach, which has a method called
getDailyWorkout();
I am doing a basic calling of a bean from the container using getBean()
Here is a main class
public static void main(String[] args) {
//load spring configuration file
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
// retrieve bean from spring container
Coach theCoach = context.getBean("myCoach", Coach.class);
//call methods on bean
System.out.println(theCoach.getDailyWorkout());
Object o = new Object();
o = theCoach;
System.out.println("this is Object before closing> "+o);
//close context
System.out.println("Closing context");
context.close();
System.out.println("After closing context");
System.out.println("this is a regular usage of bean reference> "+theCoach.getDailyWorkout());
System.out.println("this is Object AFTER closing> "+o);
Coach c = (Coach) o;
System.out.println("this is AFTER CASTING> "+c.getDailyWorkout());
}
And the output is the following
Jun 09, 2022 6:36:00 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@6d9c638: startup date [Thu Jun 09 18:36:00 CEST 2022]; root of context hierarchy
Jun 09, 2022 6:36:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Run for 20 min
this is Object before closing> com.juradent.springdemo.TrackCoach@69b0fd6f
Closing context
Jun 09, 2022 6:36:01 PM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@6d9c638: startup date [Thu Jun 09 18:36:00 CEST 2022]; root of context hierarchy
After closing context
this is a regular usage of bean reference> Run for 20 min
this is Object AFTER closing> com.juradent.springdemo.TrackCoach@69b0fd6f
this is AFTER CASTING> Run for 20 min