【发布时间】:2020-06-25 13:00:13
【问题描述】:
我已将 Eclipse 配置为警告“潜在的资源泄漏”。
我的 Spring Boot main 方法有这样的代码:
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
Eclipse 将此行检测为:Potential resource leak: '<unassigned Closeable value>' may not be closed
如果我这样设置:
public static void main(String[] args) {
try(ConfigurableApplicationContext context = SpringApplication.run(App.class, args)){
}
}
Spring Boot 立即开始和结束
2020-06-25 14:02:28.336 INFO 9108 --- [main] demo.App : Started App in 50.426 seconds (JVM running for 51.605)
2020-06-25 14:02:28.403 INFO 9108 --- [main] org.mongodb.driver.connection : Closed connection [connectionId{localValue:2, serverValue:207}] to localhost:27017 because the pool has been closed.
我该如何解决这个问题?
【问题讨论】:
标签: eclipse spring-boot memory-leaks