In a spring MVC application, I initialize a variable in one of the service classes using the following approach:
ApplicationContext context =
new C
Yes, interface ApplicationContext
doesn't have close()
method, so I like to use class AbstractApplicationContext
to use that close
method explicitly and also here you can use your Spring Application configuration class using annotation instead of XML
type.
AbstractApplicationContext context = new AnnotationConfigApplicationContext(SpringAppConfig.class);
Foo foo = context.getBean(Foo.class);
//do some work with foo
context.close();
your Resource leak: 'context' is never closed
warning is gone now.