首先聲明Mapper接口時,could not autowire,是因為idea的拼寫檢查,並不影響執行
Setting->Inspections->Spring->springCore->Code->Autowiring for Bean Class設置為nohighliting ,only fixed.即可
接下來的說”Invalid bound statement “異常,不能找到Mapper接口的代理類
1.檢查了我的配置文件,沒有問題
2.我看網上很多人說因為Idea不能編譯resources目錄下的XML文件,然后target下的classes目錄下不會生成XML文件,需要在maven項目的pom文件build下加入以下配置
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
可是我的target目下有XML等配置文件,所以不是這個問題,我使用的是IDEA 2017.2.6版本,我想idea應該新點的版本解決了這個問題.
我們知道Mybaties中,Mapper接口和XML配置文件需要在一個目錄下。
3、最后我發現我的問題是:
我的resources下的文件建立錯誤了。
eclipse的resources下可以建立pacakge,但是Idea下不能,只能建立Directory,即目錄.
所以我之前新建com.ray.mybbs.mapper.test,這顯然是一個文件夾的名稱。
正確的建立方式是com/ray/mybs/mapper/test,這樣建立多級目錄
---------------------
作者:一個宋冬野
來源:CSDN
原文:https://blog.csdn.net/ray_jone/article/details/79371448
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!