spring+mybatis集成问题

spring+mybatis集成最常见的就2个问题

1.

Description:

Field userMapper in spring_boot.service.impl.UserServiceImpl required a bean of type 'spring_boot.mapper_2.UserMapper' that could not be found.
Action:

Consider defining a bean of type 'spring_boot.mapper_2.UserMapper' in your configuration.

映射文件mapper没有找到 项目启动之后!

2.

Invalid bound statement (not found): spring_boot.mapper_2.UserMapper.selectByPrimaryKey

绑定的属性值 没有找到  就是说 mapper的xml文件没有找到它的对应方法接口类

说白啦 就是在配置加载mapper.xml和mapper接口那里出现了问题 总的来就也就是一个问题而已

在eclipse开发springboot环境下 其中要求mapper.xml和mapper接口类必须要在同一路径下 要不然机器是找不到的

而springboot加载mapper.xml配置方式有两点 

1是把配置放在application.properties里

如:mybatis.mapper-locaitons=classpath:spring_boot/mapper_2/*.xml 

2是通过在启动类里加上注解扫描:@MapperScan("spring_boot.mapper_2")//mapper包类路径

但是不管你用哪种方式在eclipse开发springboot环境下 其中要求mapper.xml和mapper接口类必须要在同一路径下

所有当你把mapper.xml文件放在application.properties在注解@MapperScan("spring_boot.mapper_2")//mapper接口类

其实是累赘的  应为你必须要把 mapper.xml和mapper接口类必须要在同一路径下

所有 你只需配置注解@MapperScan("spring_boot.mapper_2") 就可以啦 其中在mapper_2包下必须是包含mapper.xml和mapper接口

猜你喜欢

转载自blog.csdn.net/rainjm/article/details/80748032