Compiling environment: Eclipse
Problem: in spring MVC applications, I use the following method to initialize variables in one of the service classes
ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj=(HelloWorld) context.getBean("helloWorld");
obj.getMessage();
In the first line of the above code, the ‘context’ variable generates a warning. The warning is as follows:
Resource leak: 'context' is never closed
Solution: because ApplicationContext has an instance of classpathxmlapplicationcontext, it has a close () method. We just need to throw the context object and call the close () method, as shown below.
((ClassPathXmlApplicationContext) context).close();
In addition, if the ApplicationContext uses an abstractapplicationcontext instance, you need to throw the context object of that type and call the close () method.
import org.springframework.context.support.AbstractApplicationContext;
...
...
...
...
((AbstractApplicationContext) context).close();
Read More:
- Spring configuration transaction, JUnit unit test error “failed to load ApplicationContext”
- Spring boot running appears java.lang.IllegalStateException : Failed to load ApplicationContext
- spring boot-beans in application context form a cycle
- Solution to the error of @ resource annotation in eclipse spring
- Spring MVC – enable static resource access
- Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package
- Android avoids memory leak: reasonable use of getcontext() and getapplication ()
- Spring nested exception is java.lang.NoClassDefFoundError: org/springframework/core/MethodClassKey
- Unable to read scheme document‘ http://www.springframework.org/schema/spring-context.xsd The solution to the problem
- The spring boot set appears in the stand-alone version of redis Servlet.service () for servlet [dispatcherServlet] in context with path [] thr
- 0xc015000f: the activation context being deactivated is not recently activated
- The difference, cause and solution of memory overflow and memory leak
- The remote host closed the connection. The error code is 0x80072746.
- When the spring MVC project is running on idea, an error is reported when the controller is a null pointer
- Spring AOP is an error creating bean with name
- Failed to commit changes to dconf: the connection is closed
- Spring cloud is a big hole. Failed to start bean ‘eurekaAutoServiceRegistration’
- Beego method to find memory leak get memprof
- When a system is deployed on weblogic12.2.1.3, it reports an error “IllegalStateException zip file closed”. When it is deployed on weblogic12.2.1.2, it does not report an error and can be accessed normally.
- After Vue is packaged, a blank page appears, an error is reported in the resource request, and there is no error handling scheme