初学MyBatis报错 The project was not built due to "Could not delete ''.". Fix the problem, then try ref
主要代码
1、MyBatis-config.xml*
<!-- 第一种方式:设置properties -->
<configuration>
<properties resource="database.properties"/>
<!-- 注: 如果两种方式同时进行设置,则会先执行property子节点中的配的值,
然后会去读取resource的文件中的值,如果有相同的属性名则会覆盖property,
结论:resource引入的文件属性值的优先级高于property子节点中配的值-->
<properties>
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/smbms"/>
<property name="username" value="root"/>
<property name="password" value="1998"/>
</properties>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
<typeAliases>
<!-- <typeAlias type="cn.smbms.pojo.User" alias="user"/> -->
<package name="cn.smbms.pojo"/>
</typeAliases>
<!--通过default属性指定一个默认运行环境ID -->
<environments default="development">
<environment id="development">
<!-- 事务管理器两种 JDBC/MANAGED-->
<transactionManager type="JDBC"/>
<!-- 数据源类型三种UNPOOLED | POOLED | JNDI -->
<!-- POOLED 使用的是连接池的原理-->
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!-- 将mapper文件加入到配置文件中 -->
<mappers>
<!-- 第一种方式:使用类资源路径获取资源-->
<mapper resource="cn/smbms/dao/user/UserMapper.xml"></mapper>
<mapper resource="cn/smbms/dao/provider/ProviderMapper.xml"></mapper>
<!-- 第二种方式:使用url获取资源 -->
<!-- <mapper url="file:///D:/UserMapper.xml"></mapper> -->
</mappers>
2、UserMapper.xml(实体类User表与sql语句之间的映射)
3、单元测试代码
以上代码主要做对User用户表的个数进行统计,并输出统计结果,第一次运行报了下面这个错。
- (0 ms) - 2019-1-3 11:01:57DEBUG Logging initialized using ‘class org.apache.ibatis.logging.log4j.Log4jImpl’ adapter.
- (4 ms) - 2019-1-3 11:01:57DEBUG Logging initialized using ‘class org.apache.ibatis.logging.log4j.Log4jImpl’ adapter.
- (18 ms) - 2019-1-3 11:01:57DEBUG PooledDataSource forcefully closed/removed all connections.
- (18 ms) - 2019-1-3 11:01:57DEBUG PooledDataSource forcefully closed/removed all connections.
- (19 ms) - 2019-1-3 11:01:57DEBUG PooledDataSource forcefully closed/removed all connections.
- (19 ms) - 2019-1-3 11:01:57DEBUG PooledDataSource forcefully closed/removed all connections.
在进行程序调试后,发现程序在执行到以下这句
跳出了try块进入异常处理catch块,所以初步判断是MyBatis-config.xml文件编写有误,在xml文件更改正确后,重新执行方法时,控制台又报出以下错误,并且项目名一直标红色的×角标,但是项目中实际上没有报错的文件。
错误原因
在项目中对java文件或xml文件进行修改后,造成已编译的class文件与现有java文件不匹配,需要重新编译
解决方案
右击项目–source–Clean Up—清除项目中已生成的class文件,重新编译,刷新项目,如果问题还是没有得到解决那就重启eclipse或重启电脑就ok了。