由 maven + spring + mybatis 项目集成创建的想法报错,无法创建 bean
最编程
2024-03-02 20:29:41
...
最近在做一个由maven构建的spring+spring mvc+mybatis项目,刚开始的时候是用自己的电脑Win10环境下的eclipse写的,托管到了码svn上面,刚开始什么问题都没有
同学用的是win10+idea,结果问题就来了,下载下来的代码居然不能运行!!!,各种看着一脸懵逼的报错信息(idea的tomcat运行日志文件很不好找,找了好久)辛辛苦苦弄了一周左右,期间经历了把项目删了又建,然后自己搭环境等各种坑爹的环节,一开始报错信息千奇百怪,在弄了这么久之后大概就稳定成了如下的样子:
- mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/scpchome/dao/mapping/*.xml]: class path resource [com/scpchome/dao/mapping/] cannot be resolved to URL because it does not exist
一直是不能创建bean的样子,经过一行一行地阅读报错信息。。最后发现mybatis的映射xml文件居然没有找到,然后又去翻classes目录,结果果然没有,知道具体的错误就好办了,随后百度了一发在pom文件中加入了如下代码,困扰了一周的问题成功解决
<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
上一篇: TortoiseSVN 分支的创建、合并和删除 - 3.
下一篇: SVN 创建分支并合并代码