- 项目初构建好后注入Mapper 提示
Could not autowire. No beans of 'xxxxMapper' type found
,要给映射接口加个@Component接口 - vhr项目构建好的第二个问题,后端接口,用了springsecurity,但是login页面登录却说
Invalid bound statement (not found)
,后台也报错
翻阅资料发现这种情况出现有这几种情况:
- mapper.xml 里面的 namespace与实际类不一样
- mapper接口的函数名称和mapper.xml里面的标签id不一致
- 构建没有进去,请看一下target文件夹下面这些是否存在xml文件,没有请重新构建
- 扫包是否添加,一般在springboot启动类上面加注解
@MapperScan("club.popolee.vhr.mapper")
我恰巧属于第三种情况,然后解决方案是在pom.xml 里面加打包的配置如下
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
最奇怪的事情来了,我本来的pom.xml里就有这个配置,但是没生效,xml文件打包还是没进target里面,然后我就把<include>**/*.xml</include>
改为<include>**/*</include>
,改了后就莫名其妙可以了,大无语事件!