Comments (18)
I think that's a good idea.
from spring-boot-starter.
While waiting for this fix, is there anyway to disable the MapperScan from happening? Any example?
from spring-boot-starter.
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.
from spring-boot-starter.
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:
@Configuration
@MapperScan("dummy")
public class MybatisConfig {
@Bean
public ActualMapper mapper(SqlSessionFactory sqlSessionFactory){
SqlSessionTemplate sessionTemplate = new SqlSessionTemplate( sqlSessionFactory );
return sessionTemplate.getMapper(ActualMapper.class);
}
}
dummy package contains an interface:
public interface DummyMapper {
}
whereby my mybatis-config.xml has some mappers
hope this will help someone ...
from spring-boot-starter.
Good to know! BTW, I am curious about this. Do you want to turn off scanning? if so, why?
from spring-boot-starter.
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:
mybatis:
scanning: true
from spring-boot-starter.
@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?)
from spring-boot-starter.
Hi @emacarron
I registered all the mappers by using this way:
@Configuration
@MapperScan("dummy") // required since version 1.0.2
public class MybatisConfig {
@Bean
public ActualMapper1 mapper(SqlSessionFactory sqlSessionFactory){
SqlSessionTemplate sessionTemplate = new SqlSessionTemplate( sqlSessionFactory );
return sessionTemplate.getMapper(ActualMapper1.class);
}
@Bean
public ActualMapper2 mapper(SqlSessionFactory sqlSessionFactory){
SqlSessionTemplate sessionTemplate = new SqlSessionTemplate( sqlSessionFactory );
return sessionTemplate.getMapper(ActualMapper2.class);
}
}
whereby mybatis-config.xml has some mappers
spring-boot-starter works with this pattern since 1.0 π
from spring-boot-starter.
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?
from spring-boot-starter.
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?
repo: https://oss.sonatype.org/content/repositories/snapshots/
from spring-boot-starter.
OK, i agree with your decision !!
I think this change should will be announced expressly on release note.
Thanks!
from spring-boot-starter.
Sure. And thanks for your opinion!
from spring-boot-starter.
My boilerplate way is still better than having this log appearing
2016-04-08 14:20:33.381 WARN 4828 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'XXXRepository' and 'XXXRepository' mapperInterface. Bean already defined with the same name!
And for trying to do this :-)
@MapperScan("pkg1,pkg2,pkg3,pkg4")
from spring-boot-starter.
You can specify a pattern in basepackage. You may want to try that.
El 8 abr. 2016 8:41 a. m., "Ian Lim" [email protected] escribiΓ³:
@emacarron https://github.com/emacarron
My boilerplate way is still better than having this log appearing
2016-04-08 14:20:33.381 WARN 4828 --- [ main] o.m.s.mapper.ClassPathMapperScanner : Skipping MapperFactoryBean with name 'XXXRepository' and 'XXXRepository' mapperInterface. Bean already defined with the same name!
And for trying to do this :-)
@MapperScan("pkg1,pkg2,pkg3,pkg4")
β
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#46 (comment)
from spring-boot-starter.
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?
from spring-boot-starter.
This is a very good idea π
from spring-boot-starter.
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?
from spring-boot-starter.
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
from spring-boot-starter.
Related Issues (20)
- Update the autoconfigurer to track mybatis-spring (currently on 3.0.4) HOT 1
- MybatisCursorItemReader#open, close inherit deprecated method HOT 1
- Switch baseline to Spring Boot 3.2.x HOT 5
- Update to MyBatis Spring 3.0.3-SNAPSHOT for supporting Spring Boot 3.2
- Update to Spring Boot 2.7.x latest version on 2.3.x branch HOT 2
- Support JDK 22 on CI HOT 1
- Site distribution will be broken for the moment due to multi module
- Can I specify the databaseId directly? HOT 1
- When is the 3.0.3 release scheduled? HOT 3
- Unable to customize settings using ConfigurationCustomizer/SqlSessionFactoryBeanCustomizer
- Mapping error for some types ORA-03115 HOT 1
- Error access org.mybatis.spring.SqlSessionFactoryBean HOT 4
- Mybatis configuration of type aliases package path in yaml file does not take effect
- Incompatible type between Configuration SqlSessionFactoryBean and MybatisProperties HOT 5
- The MapperScannerConfigurer should support FactoryBeans HOT 1
- In Spring Boot 3.2.5 and mybatis-plus-boot-starter 3.5.6, the system encounters an error during initialization : Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required HOT 4
- Combability with Spring Boot 3 HOT 2
- Plans to support Spring Boot 3.3.0? HOT 2
- MyBatis Cache Per Request: Should Be Cleared When a Request Ends HOT 5
- :sparkles: Support MyBatis for Spring Boot 3 Native HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot-starter.