"Type interface is not known to the MapperRegistry" exception using mybatis

47,022

Solution 1

OK, got it - this is happening because I was using a XML file for the configuration, and annotations for the mappers themselves - and mybatis doesn't find mapper annotations when using an XML config.

See this followup question.

Solution 2

just for anyone who ended up here because they're new to mybatis http://www.mybatis.org/core/configuration.html
http://www.mybatis.org/mybatis-3/configuration.html

in the config file mappers section

<mappers>
<mapper class="my.package.com.MyClass"/>
</mappers>

this will have you up and running with a config.xml and annotated interfaces

Solution 3

add Mapper class to your SqlSessionFactory Configuration as this:

SqlSessionFactory factory = new SqlSessionFactoryBuilder()
            .build(reader);

//very import
factory.getConfiguration().addMapper(BarMapper.class);

SqlSession sqlSession = factory.openSession();

Solution 4

In your mapper.xml file mapper's namespace should be the path to the mapper interface.

for example:

<mapper namespace="com.mapper.LineMapper">
<select id="selectLine" resultType="com.jiaotong114.jiaotong.beans.Line">
select * from bus_line where id = #{id}
</select>
</mapper>

your mapper interface should be in com.mapper package and the name of it is LineMapper.

Solution 5

Type interface org.domain.classmapper is not known to the MapperRegistry

MyBatis throws this exception if the full package / class is not entered into the mapper xml namespace.

e.g. <mapper namespace="classmapper"> causes exception, but

<mapper namespace="org.domain.classmapper"> works

Share:
47,022
ripper234
Author by

ripper234

See blog or LinkedIn Profile

Updated on July 09, 2022

Comments

  • ripper234
    ripper234 almost 2 years

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

    org.apache.ibatis.binding.BindingException: Type interface org.foo.Bar is not known to the MapperRegistry

    Googling it doesn't find anything, nor the user guide. What am I missing?