1.运行测试用例发现找不到mapper.xml映射文件
改进前:
可以发现dao里面没有xml文件,而且像spring和mybatis的config文件有点时候也不会出现在class路径下面。
改进方法
pom.xml里面添加
<resources>
<resource>
<directory>src/main/java</directory><!--所在的目录-->
<includes><!--包括目录下的.properties,.xml 文件都会扫描到-->
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
然后点击
接着依次点击clean和compile就行了
改进后的效果
xml出现在了dao包里面
2.开启spring事务的注解tx:annotation-driven报错
解决办法
在约束文件里面手动加上(它不会自动加上)
xmlns:tx="http://www.springframework.org/schema/tx"
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
这关键的三句就可以了,加的位置如下图蓝色框所示
3.ClassPath类路径
一般情况下,resources资源文件夹里面的东西都会在生成的target的class文件夹根目录,而其他的资源文件是不会生成的,需要在pom里面指定过滤才行。