在学习spring-mybatis过程中
写好了spring-dao.xml(用spring配置实现mybatis-config.xmlde 文件)的配置以后,发现报错
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: ***Error creating bean with name 'datasource' defined in class path resource [spring-dao.xml]: Error setting property values;*** nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: ***Property 'driverClassName' threw exception;*** nested exception is java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;
度娘以后说是注入出现问题,没排出错,后来看视频后才发现
emmmmm 可能是导错包的问题
要注意pom.xml文件中spring-jdbc不应当是***springframework***
而应当是org.springframework
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>1.2.6</version>
</dependency>
正确为
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.9.RELEASE</version>