SpringBoot启动异常:This is very likely to create a memory leak. Stack trace of thread

时间:2024-05-19 18:52:28

错误信息

警告: The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:158)

 com.mysql.jdbc.NonRegisteringDriver$1.run(NonRegisteringDriver.java:93)

截图

附图如下:

SpringBoot启动异常:This is very likely to create a memory leak. Stack trace of thread

问题定位

错误信息开头有这样一段描述:

log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

很明显看出log4j没有找到配置文件。

而实际代码里有log4j.properties配置文件,由此我打开编译后打包的jar包文件,发现resource目录并没有编译出来。

而编译不出来的缘由,要么是程序某个编译错误异常阻止编译,要么是pom.xml文件关于编译的配置指定出现了问题。

于是发现pom.xml有这样的配置:

<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>

    <!--指定资源的位置-->
    <resource>
        <directory>src/main/resources/*</directory>
    </resource>
</resources>

错误原因为:src/main/resources/*

此处不应该有/*,把/*去掉,问题解决!

为什么idea可以运行,而打包后的jar包运行不了

由于pom.xml文件的配置是后面修改的,而idea有这样的功能

SpringBoot启动异常:This is very likely to create a memory leak. Stack trace of thread

也就是说,你的resources已经被识别成资源文件了,使用idea默认编译会将该目录带出,而使用纯maven打包由于配置错误,没有带出resources资源,因此会出现这种现象。