“Type interface is not known to the MapperRegistry” exception using mybatis

前端 未结 7 676
野性不改
野性不改 2021-02-02 15:23

I\'m setting up mybatis using annotations, and getting this helpful exception

org.apache.ibatis.binding.BindingException: Type interface org.foo.Bar is

7条回答
  •  别跟我提以往
    2021-02-02 15:32

    It may be that your mapper.xml file is using the incorrect namespace (perhaps because of a copy paste error).

    For instance, let's say you have a Java interface called MyEntityMapper.java that should be linked to a mybatis mapper xml config called MyEntityMapper.xml:

    MyEntityMapper.java

    package my.mappers;
    
    public interface MyEntityMapper {
        MyEntity getById(@Param("id") String id);
    }
    

    MyEntityMapper.xml

    
    
    
    
    
        
            
        
    
        
    
    

    Notice that the namespace attribute on the element in MyEntityMapper.xml is pointing to some non-existent mapper non.existent.package.NonExistentMapper, when really it should be pointing to my.mappers.MyEntityMapper.

提交回复
热议问题