【巨坑】SpringBoot创建Bean失败 + 内存泄漏警告 The web application [ROOT] appears to have started a thread named

2年前 (2022) 程序员胖胖胖虎阿
394 0 0

最近在做一个项目,今天稍微修改了一些mapper和service、加了一个controller后,项目启动突然警告 + 报错(为了保证可读性加了一些换行):

2022-02-08 22:28:08.024  WARN 65348 --- [           main] o.a.c.loader.WebappClassLoaderBase       : 
The web application [ROOT] appears to have started a thread named [logback-1] but has failed to stop it. 
This is very likely to create a memory leak. Stack trace of thread:
 java.base@11.0.12/jdk.internal.misc.Unsafe.park(Native Method)
 java.base@11.0.12/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:234)
 java.base@11.0.12/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2123)
 java.base@11.0.12/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1182)
 java.base@11.0.12/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:899)
 java.base@11.0.12/java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1054)
 java.base@11.0.12/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1114)
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-08 22:28:08.044 ERROR 65348 --- [           main] o.s.boot.SpringApplication               : 
Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'classCacheConfig': Unsatisfied dependency expressed through field 'classService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'classServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'classMapper' defined in file [C:\Users\CTC\Desktop\ZKCOURSE\target\classes\com\haotongxue\mapper\ClassMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\Users\CTC\Desktop\ZKCOURSE\target\classes\com\haotongxue\mapper\xml\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: 
Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 36; columnNumber: 10; The content of element type "mapper" must match "(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*)+".

除此之外,还显示了其他一些service和mapper的创建Bean失败异常(此处省略),仔细检查了一番各个Bean的写法和使用后,还是找不到问题出现在哪里。对比Git版本后,发现我也没有动过相关Bean,检查了很久才发现原来mapper.xml有个地方多写了一些东西,导致标签无法匹配…
【巨坑】SpringBoot创建Bean失败 + 内存泄漏警告 The web application [ROOT] appears to have started a thread named
在底部也可以发现mapper标签已经报红:
【巨坑】SpringBoot创建Bean失败 + 内存泄漏警告 The web application [ROOT] appears to have started a thread named
回想才知道可能在粘贴方法名的时候不小心。但是idea中的xxxMapper.xml文件却没有报红,特别是我们在日常code的时候,很容易忽略这些藏在文件里的报红细节。

将这串多出来的字母删去后,一切恢复正常。
其实在报错信息的一些列“Caused by…”中,除了前面的一大堆

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xxx’

信息外,在底部还有一串:

Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [C:\Users\CTC\Desktop\xxxxx\target\classes\com\xxxxx\mapper\xml\UserMapper.xml]’;

还有一串:

Caused by: org.apache.ibatis.builder.BuilderException: Error creating
document instance. Cause: org.xml.sax.SAXParseException; lineNumber:
36; columnNumber: 10; The content of element type “mapper” must match

从中可以看出,其实编译器已经提醒我们错误具体在哪个文件里了,甚至行数和列数也给我们了(虽然是不准的),只是被我忽略了…

但是为什么会出现那么多Bean创建失败的情况呢?报错的绝大多数Bean也没有直接引用这个mapper组件,而且还出现了内存泄漏(Memory leak)的多条警告,欢迎各位大佬交流指教o(╥﹏╥)o

相关文章

暂无评论

暂无评论...