警告:org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’
defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/DaoSupport …(省略了一些错误) Caused by: java.lang.ClassNotFoundException: org.springframework.dao.support.DaoSupport at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) … 91 more
Process finished with exit code -1
解决
- 首先确保Spring配置文件application.xml(spring.xml)下的包扫描配置是否拼写错误
正确写法:
<!--扫描mapper所在的包,为mapper创建实现类(若使用此方法,接口Mapper与其映射文件的全限定名需一致)-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ayi.dao"/>
<property name="sqlSessionFactoryBeanName" value="SessionFactory"/>
</bean>
- 查看pom是否缺失以下依赖(有些文章说是缺失spring-tx)
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.17</version>
</dependency>
正常来说应该是可以了,但我在添加完spring-jdbc后出现了新的报错,原来是mysql-connector依赖过旧,更换为8.0.28后成功运行。
|