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?
add Mapper class to your SqlSessionFactory Configuration as this:
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.
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 calledMyEntityMapper.xml
:MyEntityMapper.java
MyEntityMapper.xml
Notice that the
namespace
attribute on the<mapper>
element inMyEntityMapper.xml
is pointing to some non-existent mappernon.existent.package.NonExistentMapper
, when really it should be pointing tomy.mappers.MyEntityMapper
.In your mapper.xml file mapper's namespace should be the path to the mapper interface.
for example:
your mapper interface should be in com.mapper package and the name of it is LineMapper.
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">
worksHappened to me when creating a shadowJar/bootJar for a spring boot project and using org.springframework.boot gradle plugin
When the jars are zipped inside the bootJar myBatis may fail to find the XML configuration files and will throw the described exception
adding this block in the build.gradle file:
solved my problem