Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Mybatis mapper scanner picking up wrong class
    text
    copied!<p>I use Spring with Mybatis. I have it configured to scan for mappers in my whole project and I assumed it determined a mapper because it found an XML file which has reference to a java interface.</p> <p>But this is proven incorrect today because I had to add a new interface which is not a mapper class and Mybatis thinks it is, so it is causing problems in my app due to this error:</p> <p>Mapped Statements collection does not contain value for com.blah.MyInterface.someMethod</p> <p>com.blah.MyInterface is just a simple interface which I needed to be included in Spring context so I gave it the @Component tag. Is that the wrong tag to use? Is that where the confusion comes from?</p> <p>I just needed to create this interface so that I can have a proxy wrap my database calls in one place where I can put a @Transactional tag, since Spring ignores it when it is in my Controller method.</p> <p>Sample code</p> <pre><code>package com.blah.something; @Component public interface MyInterface { public void someMethod( SomeObject obj) throws Exception; } package com.blah.something; public class MyImplementation implements MyInterface { @Transactional public void someMethod( SomeObject obj) throws Exception { ... do a whole bunch of stuff } } </code></pre> <p>I dont want this included in the MyBatis mappers! </p> <p>Edit: added the mybatis config xml as requested:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"&gt; &lt;configuration&gt; &lt;settings&gt; &lt;setting name="lazyLoadingEnabled" value="false" /&gt; &lt;setting name="defaultStatementTimeout" value="60"/&gt; &lt;/settings&gt; &lt;typeAliases&gt; &lt;typeAlias alias="StripTrailingZerosBigDecimalTypeHandler" type="com.blah.typehandlers.StripTrailingZerosBigDecimalTypeHandler"/&gt; &lt;/typeAliases&gt; &lt;/configuration&gt; </code></pre> <p>This is the part of my spring xml config which calls the mybatis mapper scanner:</p> <pre><code>&lt;bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt; &lt;property name="basePackage" value="com.blah" /&gt; &lt;/bean&gt; </code></pre> <p>So I set it to scan the whole project which includes my interface above but I can't imagine it just grabs every single interface and considers them all mappers! </p> <p>In my debug log I see mybatis picking up my interface:</p> <pre><code>12/9/13 11:18:44 904 [org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner.findCandidateComponents:4125] - Scanning file [D:\Weblogic\wls11\domains\ldapdomain\autodeploy\default\WEB-INF\classes\com\blah\MyInterface.class] 12/9/13 11:18:44 904 [org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner.findCandidateComponents:4125] - Identified candidate component class: file [D:\Weblogic\wls11\domains\ldapdomain\autodeploy\default\WEB-INF\classes\com\blah\MyInterface.class] 12/9/13 11:18:44 904 [org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner.findCandidateComponents:4125] - Scanning file [D:\Weblogic\wls11\domains\ldapdomain\autodeploy\default\WEB-INF\classes\com\blah\MyImplementation .class] 12/9/13 11:18:44 904 [org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner.findCandidateComponents:4125] - Ignored because not a concrete top-level class: file [D:\Weblogic\wls11\domains\ldapdomain\autodeploy\default\WEB-INF\classes\com\blah\MyImplementation .class] </code></pre> <p>There is no XML for this interface, there is no mapper namespace for it, it's just a plain old regular interface and MyBatis should not be thinking it is a mapper service</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload