首页 > 代码库 > 关于mybatis Invalid bound statement (not found) 问题

关于mybatis Invalid bound statement (not found) 问题

初学mybatis   现在系统是spring + mybatis  
applicationContext.xml里面配置了Mapper 自动扫描

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="http://www.mamicode.com/com.yolly.platform.*" />
</bean>

然后定义了一个userMapper,里面就只有一个方法

@Repository(value="http://www.mamicode.com/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="http://www.mamicode.com/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="http://www.mamicode.com/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="http://www.mamicode.com/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) 问题