In a spring MVC application, I initialize a variable in one of the service classes using the following approach:
ApplicationContext context = new C
try this. you need to apply cast to close applicationcontext.
ClassPathXmlApplicationContext ctx = null; try { ctx = new ClassPathXmlApplicationContext(...); [...] } finally { if (ctx != null) ((AbstractApplicationContext) ctx).close(); }