温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-23 22:34:30 来源:网络 阅读:3942 作者:qq58edf1d989a2d 栏目:开发技术

初学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


源码来源:×××/technology

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI