-
Notifications
You must be signed in to change notification settings - Fork 1.8k
All interfaces are registered as mybatis mappers even if they are not mappers #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
While waiting for this fix, is there anyway to disable the MapperScan from happening? Any example? |
Yes. Add a @MapperScan to your main application class pointing to a dummy interface. That will register a MapperFactoryBean: @SpringBootApplication
@MapperScan("dummy.package")
public class SampleMybatisApplication implements CommandLineRunner { or create a MapperFactoryBean explicitly: @Bean
MapperFactoryBean<Object> createMapper() {
return new MapperFactoryBean<Object>();
} If a MapperFactoryBean is detected autoscan is not done. |
Thanks for the example, I think this is a good material to put in the docs. If not, people will have to come to this issue and read about this... Anyway, this is what is working for my case:
dummy package contains an interface:
whereby my mybatis-config.xml has some mappers hope this will help someone ... |
Good to know! BTW, I am curious about this. Do you want to turn off scanning? if so, why? |
I am using this way to avoid all interfaces to be registered as mybatis mappers even if they are not mappers. Actually, can we have a setting to turn off the @MapperScan ? For example:
|
@mallim But... note that a mapper must be a bean in spring so it can be injected into any other bean. How are you registering your mapper? (or are you using the sqlSessionTemplate?) |
Hi @emacarron I registered all the mappers by using this way:
whereby mybatis-config.xml has some mappers spring-boot-starter works with this pattern since 1.0 👍 |
I see, but I would say you have too much boilerplate. If you set the @MapperScan() with the package name (or pattern) where your mappers are this will work fine and you can remove that two @bean methods. Can you check that? |
BTW I just have updated master so autoscanning will only pick interfaces inside **/mapper or **/mappers package as a convention (over configration). Details here: http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ @kazuki43zoo I finally decided not to include "repository" to let people mix JPA and MyBatis in the same project. Can you plese check the snapshot and let us know how it works? |
OK, i agree with your decision !! Thanks! |
Sure. And thanks for your opinion! |
My boilerplate way is still better than having this log appearing
And for trying to do this :-)
|
You can specify a pattern in basepackage. You may want to try that.
|
I have recoded this to be more aligned with Spring @configuration that is based on annotations. So I have added a @Mapper marker annotation to the core so other DI frameworks can use it (spring, boot, cdi) Thoughts? |
I think that's a good idea. |
This is a very good idea 👍 |
Hi @emacarron I didn't know about this Mapper annotation in advance so I have added one in CDI some time ago just before 1.0 release. Do you think we have to remove the cdi specific annotation and use just this? |
I am using 3.5.6 And this still happens. I think MapperScan should have default value for annotationClass equal to org.apache.ibatis.annotations.Mapper.class |
Right now, the mybatis boot starter module takes all the interfaces it founds in a project and registers them as mappers. We should be able to identify if an interface is a mapper or not.
The problem is that mappers are not annotated (the @Mapper annotation does not exist). We did this because we would like to build applications with no mybatis imports at all. So they way you select your mappers when using classic configuraiton like MapperScannerConfigurer or @MapperScan is by:
So, my proposal is to use this convention: mappers are supposed to be interfaces held in a */mapper or */mappers package.
For any other configuration, use the @MapperScan annotation that lets you configure everything.
The text was updated successfully, but these errors were encountered: