关于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

时间: 2024-10-04 18:23:09

关于mybatis Invalid bound statement (not found) 问题的相关文章

转载:Maven项目mybatis Invalid bound statement (not found)解决方法

在mapper代理的开发中,程序员需要遵守一些规范,mybatis才能实现mapper接口的代理对象. 它的规范如下: mapper.xml的namespace要写所映射接口的全称类名. mapper.xml中的每个statement的id要和接口方法的方法名相同 mapper.xml中定义的每个sql的parameterType要和接口方法的形参类型相同 mapper.xml中定义的每个sql的resultType要和接口方法的返回值的类型相同 mapper.xml要和对应的mapper接口在

MyBatis: Invalid bound statement (not found)错误的可能原因

MyBatis: Invalid bound statement (not found)错误的可能原因 其他原因导致此问题解决参考: 1.检查 xml 文件所在 package 名称是否和 Mapper interface 所在的包名一致 <mapper namespace="com.xiaopengwei.mapper.UserInfoMapper"> mapper 的 namespace 写的不对!!!注意系修改. 2.UserDao 的方法在 UserDao.xml

Mybatis:Invalid bound statement (not found)

今天在使用SSM做整合练习的时候写完初始的一个查询功能,想测试下环境是否正确,出现了这个问题, 找个半天才发现自己的问题.网上很多说Mapper.xml中的namespace写的问题,但是我出现的问题却不在这. 由于用Spring去整合Mybatis,不在需要mybatis的配置文件. 出错的时候是这样: <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&

mybatis中Invalid bound statement (not found) 和 Result Maps collection already contains value for...错误解决方案

一.Invalid bound statement (not found) 使用mybatis有时候会报Invalid bound statement (not found)这种错误,总结了下,可能有两种情况如下: 1.mybatis的对应的mapper.xml找不到对应的命名sql或者名称与mapper接口名称不一致. 2.xml文件与接口名称都对,但是在mybatis配置文件中漏掉了配置,也会报这种错误. 二.Result Maps collection already contains v

Mybatis 异常记录(1): Invalid bound statement (not found)

错误信息: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pingan.credit.dao.mapper.TdReportMapper.insertQueryLog at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:223) at org.apache.ibatis

MyBatis笔记----报错Exception in thread &quot;main&quot; org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectUser

信息: Refreshing org[email protected]41cf53f9: startup date [Wed Apr 05 16:48:12 CST 2017]; root of context hierarchy 四月 05, 2017 4:48:12 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definiti

[mybatis] mybatis错误:Invalid bound statement (not found)

点击菜单抛出异常: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.misscandy.inter.UserMapper.findAllUsers org.springframe

&quot;Invalid bound statement (not found): com.sitech.admin.dao.TbOpenAbilityInfoDao.findAbilityReadyUp&quot;mybatis配置文件bug

问题描述: 通常在正常启动某项工程后操作某个功能时抛出的bug: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.sitech.admin.dao.TbOpenAbilityInfoDao.findAbilityReadyUp at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.j

mybatis 异常处理:Invalid bound statement (not found)

mybatis 的使用过程中提示错误: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.msunsoft.mapper.HisLisReportMapper.getMaxMtcData 含义:HisLisReportMapper的getMtcData方法没有找到或者没有绑定 背景: 1.HisLisReportSyncWorker 控制类中 String hospitalCo