新手可能会遇到的错误[mybatis]
作者:互联网
------------恢复内容开始------------
问题一: Could not find resource mybatis-config.xml
当出现这个错误很明显是找不到 mybatis-config.xml文件,出现这种错误,很大一部原因是你可能没有把mybatis-config.xml文件放到resources文件目录下
问题二:
出现上面这个问题;
应该是mybatis-config.xml文件中的驱动没有配置好,
容易出错的点一个是在driver和url中
容易出错的问题是mysql配置版本在8以上,需要把driver配置成com.mysql.cj.jdbc.Driver
5.0以上8.0一下则需要把driver配置成com.mysql.jdbc.Driver
`<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/ldzy/dao/UserMapper.xml"/>
</mappers>
</configuration>`
url容易出错是url配置要完整
`name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false"
`
但也有可能是没有在pom文件中加上这段代码
`<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>`
就会导致无法把UserMapper.xml文件加载到targetx下
标签:xml,错误,url,amp,mysql,mybatis,新手,config 来源: https://www.cnblogs.com/cnmd11/p/16106889.html