最近在做一個由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>