Spring ApplicationContext - Resource leak: 'context' is never closed
編譯環境:Eclipse
問題:在spring MVC應用程式中,我使用以下方法初始化其中一個服務類中的變數
ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml");
HelloWorld obj=(HelloWorld) context.getBean("helloWorld");
obj.getMessage();
上面的程式碼中第一行程式碼'context'變數生成警告。警告如下所示:
Resource leak: 'context' is never closed
解決方法:由於ApplicationContext具有ClassPathXmlApplicationContext的例項,因此具有close()方法。我們只需要丟擲context物件並呼叫close()方法,如下所示。
((ClassPathXmlApplicationContext) context).close();
另外,如果ApplicationContext使用的是AbstractApplicationContext例項,則需要丟擲該型別的context物件並呼叫close()方法。
import org.springframework.context.support.AbstractApplicationContext;
...
...
...
...
((AbstractApplicationContext) context).close();
相關推薦
Spring ApplicationContext - Resource leak: 39;context39; is never closed
編譯環境:Eclipse 問題:在spring MVC應用程式中,我使用以下方法初始化其中一個服務類中的變數 ApplicationContext context=new ClassPathXmlApplicationContext("Beans.xml"); HelloWorld ob
錯誤日誌:Resource leak: 39;xxx39; is never closed(Scanner類的註意事項)
import sans 釋放內存 ann p s pan 函數 eve style 在使用Scanner類時,舉個例子: 1 import java.util.Scanner; 2 public class data { 3 4 public stat
TS2339:報錯;某個物件上不存在某個方法【例】:Property 39;context39; does not exist on type 39;NodeRequire39;.
簡單直接的說 報錯說某個物件上 不存在某個屬性 開始以為寫錯了 然後翻看之前的js版本 發現 引用的模組都已同樣的模組 用ts的角度說 引用的都已一個型別介面的物件 可為什麼js好使 ts就報錯呢
spring boot項目啟動報(No session repository could be auto-configured, check your configuration (session store type is 39;null39;))
ssi 問題解決 conf 重新啟動 null 增加 boot 修改 ati 找到項目的application配置文件,增加 spring.session.store-type=none,重新啟動問題解決 註:因為項目未使用redis管理session,可以如上設置,如果想
Spring Boot - Error creating bean with name 39;dataSource39; defined in class path resource
刪除 需要 reat text class with config autoconf ext 看起來像最初的問題是與自動配置。 如果你不需要數據源,只需從自動配置過程中刪除它: @EnableAutoConfiguration(exclude={DataSour
spring-boot 啟動時候 出現異常:The bean 39;xxx39; could not be injected as a 39;xx.xxxx39; because it is a JDK dynamic proxy that implements:
ng- for sed AC 存在 cti 解決方法 sid 失敗 The bean ‘xxxService‘ could not be injected as a ‘AaaXxxService‘ because it is a JDK dynamic proxy tha
Spring Boot 報錯:Error creating bean with name 39;entityManagerFactory39; defined in class path resource
fine 依賴 debug isp jpa java idt .com ima spring boot 寫一個web項目,在使用spring-data-jpa的時候,啟動報如下錯誤: Error starting ApplicationContext. To display
Android之Error: 39;L39; is not a valid file-based resource name character解決辦法
copyto base logo lower too exec article 問題 tools 1、問題 [html] view plain copy Error:Execution failed for task ‘:mergeBYODReleaseR
Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 39;dataSource39; defined in class path resource [applicationContext
Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in class path resource [applicationContext.xml]; 該錯誤是因
Error creating bean with name 39;dataSource39; defined in class path resource [spring-config.xml]: BeanP
錯誤描述: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [spring-con
Spring AOP表示式報錯:Pointcut is not well-formed: expecting 39;name pattern39; at character position
問題現象: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoader
spring-data-jpa Error creating bean with name 39;entityManagerFactory39; defined in class path resource
專案地址:https://github.com/heng1234/springdata-jpa 問題描述: 剛開始實體類程式碼是這樣寫的 package com.hvly.springjp_1.com.hlvy.entity; import lombok.Data
關於spring mvc傳參錯誤 Required String parameter 39;xxxxx39; is not present
controller如下: 1 @RequestMapping(value=("/login"), method=RequestMethod.POST) 2 public ModelAndView getUser(@RequestParam("loginName")String login
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 39;source39; web.xml is missing and <failOnMissingWebXml> is se
eclipse建立Maven結構的web專案的時候選擇Artifact Id為maven-artchetype-webapp,點選finish之後,一般會遇到如下問題 1. The superclass "javax.servlet.http.HttpServlet" was n
Spring MVC檔案上傳出現錯誤:Required MultipartFile parameter 39;file39; is not present
1.配置檔案上傳的解析器 首先需要在spring mvc的配置檔案中(注意是spring mvc的配置檔案而不是spring的配置檔案:applicationContext.xml)配置: springmvc-config.xml <!-- 檔案上傳bean--> <
java.lang.IllegalArgumentException: sheetName '' is invalid
cab val nbsp 數據庫查詢 work base pac ava bst 1、錯誤描寫敘述java.lang.IllegalArgumentException: sheetName ‘‘ is invalid - character count MUST be g
Choose unique values for the 39;webAppRootKey39; context-param in your web.xml files!
pear http unique syn all 題解 錯誤信息 不同的 sync 在Tomcat的server.xml中配置兩個context,出現其中一個不能正常啟動,交換配置順序,另一個又不能正常啟動,即始終只有第二個配置能啟動的情況。如果單獨部署,都沒有問題。報錯大
mybatis 異常 There is no getter for property named 39;bizId39; in 39;class java.lang.Long39;
img 技術分享 .com mybatis lan alt nbsp pro 錯誤 mybatis 異常 There is no getter for property named ‘bizId‘ in ‘class java.lang.Long‘ 當使用mybatis進行
python 鏈接codis 報錯解決辦法 command 39;EXEC39; is not allowed
command 'exec' is not allowed python redis codis [[email protected]/* */ ceph]# python ../pkg/redisbase.py Traceback (most recent cal
Error in library(e1071) : there is no package called 39;e107139;
library packages 學習R語言時,在安裝包的時候都是正常的,但當導入包的時候通常會出現下面的情況:libaray(e1071)Error in library(e1071) : there is no package called ‘e1071’網上有些說是包沒有裝全,需要安裝依賴包 ,