
mybatis-plus 抛出“property 'sqlsessionfactory' or 'sqlsessiontemplate' are required”异常
问题详情:
在使用 mybatis-plus 时,遇到“property 'sqlsessionfactory' or 'sqlsessiontemplate' are required”异常,而 pom 中已更新 mybatis-plus 至最新版本。
问题根源:
出现该异常通常是因为应用程序上下文中缺少 mybatis-plus 依赖关系,导致 mybatis 不能访问 sqlsessionfactory 或 sqlsessiontemplate。
解决方法:
检查应用程序上下文中是否包含以下依赖关系:
<dependency>
<groupid>org.mybatis</groupid>
<artifactid>mybatis</artifactid>
<version>3.5.9</version>
</dependency>
<dependency>
<groupid>org.mybatis</groupid>
<artifactid>mybatis-spring</artifactid>
<version>2.2.2</version>
</dependency>
<dependency>
<groupid>com.baomidou</groupid>
<artifactid>mybatis-plus</artifactid>
<version>3.4.2</version>
</dependency>检查应用程序上下文中是否已正确配置 sqlsessionfactory 或 sqlsessiontemplate bean:
<!-- 使用 SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:mapper/*Mapper.xml" />
</bean>
<!-- 使用 SqlSessionTemplate -->
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>其他提示:
以上就是Mybatis-Plus 报错“Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required”该如何解决?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号