电光石火-穿越时空电光石火-穿越时空


idea 创建的maven+spring+mybatis项目整合 报错无法创建bean

最近在做一个由maven构建的spring+spring mvc+mybatis项目,刚开始的时候是用自己的电脑Win10环境下的eclipse写的,托管到了码svn上面,刚开始什么问题都没有

同学用的是win10+idea,结果问题就来了,下载下来的代码居然不能运行!!!,各种看着一脸懵逼的报错信息(idea的tomcat运行日志文件很不好找,找了好久)辛辛苦苦弄了一周左右,期间经历了把项目删了又建,然后自己搭环境等各种坑爹的环节,一开始报错信息千奇百怪,在弄了这么久之后大概就稳定成了如下的样子:


  1. 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文件中加入了如下代码,困扰了一周的问题成功解决


  1. <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->  
  2.     <build>  
  3.         <resources>  
  4.             <resource>  
  5.                 <directory>src/main/java</directory>  
  6.                 <includes>  
  7.                     <include>**/*.properties</include>  
  8.                     <include>**/*.xml</include>  
  9.                 </includes>  
  10.                 <filtering>false</filtering>  
  11.             </resource>  
  12.         </resources>  
  13.     </build>  

QQ截图20170225215000.jpg

本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => idea 创建的maven+spring+mybatis项目整合 报错无法创建bean
本文地址:http://www.ilkhome.cn/index.php/archives/194/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 idea 创建的maven+spring+mybatis项目整合 报错无法创建bean,谢谢。

评论