SpringBootMyBatis-plus 报错 sqlSessionFactory sqlSessionTemplate 最新解决办法

Posted 叼辣条闯天涯

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBootMyBatis-plus 报错 sqlSessionFactory sqlSessionTemplate 最新解决办法相关的知识,希望对你有一定的参考价值。

本文针对 MyBatis-plus,对于 MyBatis 报相同的错误,可以看这个大佬的文章:SpringBoot3整合MyBatis报错:Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required

针对报错如下:

Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

其他的帖子大多都停留在 SpringBoot 2版本时代,MyBatis 在2022年11月才对 SpringBoot 3 提供支持,MyBatis-plus 在 12月28号才同步支持,如果其他文章不能解决该报错,那么新的途径如下。

方法1: 就用SpringBoot 3(反骨)

如果 pom.xml 中spring-boot-starter-parent 的版本 需要 使用 3.0.0 或以上,则 mybatis-plus-boot-starter 的版本必须为 3.5.3 或以上。对应如下两部分代码:
<parent> 部分:

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.1</version>
        <relativePath/>
    </parent>

<dependency> 部分:

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.3</version>
        </dependency>

方法2:不需要使用SpringBoot 3

如果 pom.xml 中spring-boot-starter-parent 的版本 不需要 使用 3.0.0 或以上,则可以将其版本改为 2.7.8 即 SpringBoot 2 版本, mybatis-plus-boot-starter 的版本无需使用最新的 3.5.3(mybatis-plus 在 3.4 和 3.5 版本之间有较大变化,按需使用即可)。
<parent> 部分:

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.8</version>
        <relativePath/> 
    </parent>

<dependency> 部分:

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.3</version> <!-- 自定义版本即可 -->
        </dependency>

JRebel启动报错

参考技术A 项目概况:SpringMVC

新接手的项目,安装JRebel插件(JRebel for IntelliJ v2019.1.1)后,启动报错,在此之前是可以正常启动项目。

报错核心信息: Exception in thread "Timer-RefreshDataTask" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

报错详细信息:

五月 10, 2019 10:37:36 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

严重: The web application [/edi-web] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

五月 10, 2019 10:37:36 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

严重: The web application [/edi-web] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

五月 10, 2019 10:37:36 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc

严重: The web application [/edi-web] registered the JDBC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

五月 10, 2019 10:37:36 上午 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks

严重: The web application [/edi-web] created a ThreadLocal with key of type [net.sf.json.AbstractJSON.CycleSet] (value [net.sf.json.AbstractJSON$CycleSet@52abeb56]) and a value of type [java.lang.ref.SoftReference] (value [java.lang.ref.SoftReference@73639524]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

[2019-05-10 10:37:36,507] Artifact xbwl-edi-web:war exploded: Error during artifact deployment. See server log for details.

log4j:WARN No appenders could be found for logger (org.springframework.scheduling.quartz.SchedulerFactoryBean).

log4j:WARN Please initialize the log4j system properly.

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

五月 10, 2019 10:37:45 上午 org.apache.catalina.loader.WebappClassLoader loadClass

信息: Illegal access: this web application instance has been stopped already.  Could not load org.springframework.core.NestedExceptionUtils.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.

java.lang.IllegalStateException

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

at org.springframework.core.NestedRuntimeException.<clinit>(NestedRuntimeException.java:45)

at org.springframework.scheduling.quartz.SchedulerFactoryBean$1.run(SchedulerFactoryBean.java:673)

Exception in thread "Quartz Scheduler [SYSSTATIC_SCHEDULE]" java.lang.NoClassDefFoundError: org/springframework/core/NestedExceptionUtils

at org.springframework.core.NestedRuntimeException.<clinit>(NestedRuntimeException.java:45)

at org.springframework.scheduling.quartz.SchedulerFactoryBean$1.run(SchedulerFactoryBean.java:673)

Caused by: java.lang.ClassNotFoundException: org.springframework.core.NestedExceptionUtils

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

... 2 more

Exception in thread "Timer-RefreshDataTask" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)

at com.xbwl.core.cache.CacheManager.<init>(CacheManager.java:20)

at com.xbwl.core.cache.CacheManager.getInstance(CacheManager.java:54)

at com.xbwl.core.mq.rabbitMq.service.impl.RabbitMqServiceImpl$RefreshDataTask.run(RabbitMqServiceImpl.java:107)

at java.util.TimerThread.mainLoop(Timer.java:555)

at java.util.TimerThread.run(Timer.java:505)

Exception in thread "Timer-RefreshDataTask" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)

at com.xbwl.core.cache.CacheManager.<init>(CacheManager.java:20)

at com.xbwl.core.cache.CacheManager.getInstance(CacheManager.java:54)

at com.xbwl.core.mq.MqInterceptor.initMqCache(MqInterceptor.java:70)

at com.xbwl.core.mq.MqInterceptor.access$000(MqInterceptor.java:26)

at com.xbwl.core.mq.MqInterceptor$RefreshDataTask.run(MqInterceptor.java:64)

at java.util.TimerThread.mainLoop(Timer.java:555)

at java.util.TimerThread.run(Timer.java:505)

Exception in thread "Timer-RefreshDataTask" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)

at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)

at com.xbwl.core.cache.CacheManager.<init>(CacheManager.java:20)

at com.xbwl.core.cache.CacheManager.getInstance(CacheManager.java:54)

at com.xbwl.core.service.impl.BaiduWebApiServiceImpl$RefreshDataTask.run(BaiduWebApiServiceImpl.java:41)

at java.util.TimerThread.mainLoop(Timer.java:555)

at java.util.TimerThread.run(Timer.java:505)

暂未解决,待续

以上是关于SpringBootMyBatis-plus 报错 sqlSessionFactory sqlSessionTemplate 最新解决办法的主要内容,如果未能解决你的问题,请参考以下文章

计算机毕业设计之全网最好的SpringBoot物业管理系统

计算机毕业设计之SpringBoot+LayUI人力资源管理系统

JRebel启动报错

tomcat 500报错

tensorflow报错 或者 keras报错 以及tf.keras报错: OOM 显存不足

idea @Autowired 报错