使用ioc注入 没有用到mapper 但是却报了org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
时间: 2023-10-27 10:54:10 浏览: 35
这个错误通常是因为 MyBatis 没有找到对应的 Mapper 文件或者 Mapper 文件中没有定义对应的 SQL 语句。
如果在使用 Spring 的时候出现这个问题,可以检查以下几个方面:
1. 检查 Mapper 文件的命名空间是否正确。
2. 检查 Mapper 文件是否在 MyBatis 的配置文件中被正确地引入了。
3. 检查 Mapper 文件中是否定义了正确的 SQL 语句,并且 SQL 语句的 id 与注解中的 value 值一致。
如果以上都没有问题,可以考虑在 Mapper 接口中使用 @Mapper 注解或者在启动类上使用 @MapperScan 注解,来让 Spring 扫描并生成 Mapper 实例,从而解决问题。
相关问题
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu.blog.service.UserService.login
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.atguigu.blog.service.UserService.login 这个错误信息表示在绑定语句时找不到com.atguigu.blog.service.UserService类中的login方法。根据引用,这是一个嵌套异常。根据引用,可以将该错误信息翻译成中文为"嵌套异常:无法绑定当前com.atguigu.blog.service包下的UserService类的login方法"。根据引用中提到的解决方法,可能是由于在Spring Mybatis MP项目中直接调用mybatis-plus插件的sql方法导致的。你可以尝试按照引用中的解决方法配置扫描器,将mybatis接口加入到IOC容器中,然后再进行调用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):xxx问题](https://blog.csdn.net/lvoelife/article/details/128017529)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.service.UserSer](https://blog.csdn.net/qq_38140033/article/details/126018287)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
引用一个ioc中的service接口 没有用到mapper 但是却报了数据库绑定异常 这是为什么 怎么解决
这种情况可能是因为在你的项目中使用了自动配置的数据源,但是你的 service 接口中没有使用 mapper,但是在接口的实现类中却使用了 mapper,导致数据库绑定异常。
解决方法可以尝试以下几个方案:
1. 在你的 service 接口上添加 `@Transactional(propagation = Propagation.NOT_SUPPORTED)` 注解,表示不支持事务,即不与数据库绑定。
2. 在你的项目的配置文件中,将自动配置的数据源关闭,然后手动配置数据源,并且只在需要使用数据库的地方使用手动配置的数据源。
3. 在你的 service 接口中添加一个空的方法,同时在方法上添加 `@Mapper` 注解,这样可以让 mapper 与数据库进行绑定,而不会影响你的代码逻辑。
希望这些解决方法能够帮到你。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)