关于mybatis Invalid bound statement (not found) 问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于mybatis Invalid bound statement (not found) 问题相关的知识,希望对你有一定的参考价值。
初学mybatis 现在系统是spring + mybatis
applicationContext.xml里面配置了Mapper 自动扫描
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yolly.platform.*" />
</bean>
然后定义了一个userMapper,里面就只有一个方法
@Repository(value="userMapper")
public interface UserMapper {
public List<User> getAll();
}
下面是userMapper.xml
<mapper namespace="com.yolly.platform.user.mapper.UserMapper">
<select id="getAll" resultType="user">
select * from user
</select>
</mapper>
下面是mybatis 配置文件
<configuration>
<settings>
<setting name="cacheEnabled" value="true" />
</settings>
<typeAliases>
<typeAlias alias="user" type="com.yolly.platform.user.entity.User"/>
</typeAliases>
<mappers>
<mapper resource="mappers/UserMapper.xml" />
</mappers>
</configuration>
我业务层定义了一个接口 UserService 然后 下面是实现类
@Component(value="userServiceImpl")
@Transactional
public class UserServiceImpl implements UserService{
private UserMapper userMapper;
@Autowired
public void setUserMapper(UserMapper userMapper) {
this.userMapper = userMapper;
}
public List<User> getAll() {
return userMapper.getAll();
}
}
我spring 配置文件加载完成后运行下面的代码可以获取结果
UserServiceImpl userServiceImpl = (UserServiceImpl)PlatformContext.getApplicationContext().getBean("userServiceImpl");
List<User> lista = userServiceImpl.getAll();
但是我现在又写了一个类 叫UserComponent 如下:
@Component(value="userComponent")
public class UserComponent {
private UserService userService;
@Autowired
public void setUserService(UserService userService) {
this.userService = userService;
}
public List<User> getAll(Head head){
return userService.getAll();
}
}
我这个UserService直接注入了
UserComponent userComponent = (UserComponent)PlatformContext.getApplicationContext().getBean("userComponent");
List<User> list = userComponent.getAll();
我像这样调用的时候就不行了,只是多加了一层啊,这是为啥,求解!
下面是异常信息:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yolly.platform.user.service.UserService.getAll
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:178)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)
at $Proxy12.getAll(Unknown Source)
at com.yolly.platform.user.component.UserComponent.getAll(UserComponent.java:25)
at com.yolly.core.main.Server$ServerHandler.messageReceived(Server.java:101)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.yolly.platform.user.service.UserService.getAll
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608)
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:176)
... 16 more
源码来源:minglisoft.cn/technology
以上是关于关于mybatis Invalid bound statement (not found) 问题的主要内容,如果未能解决你的问题,请参考以下文章
IDEA:springboot框架使用mybatis-generator插件报错:org.apache.ibatis.binding.BindingException: Invalid bound s
IDEA:springboot框架使用mybatis-generator插件报错:org.apache.ibatis.binding.BindingException: Invalid bound s
mybatis-plus 调用自带方法报错 Invalid bound statement
mybatis-plus 调用自带方法报错 Invalid bound statement
mybatis-plus 调用自带方法报错 Invalid bound statement
关于idea 中使用mybastis报出 Invalid bound statement (not found)的错误解决方案