Open RushPVA opened 7 years ago
here is a sample : https://github.com/hatunet/spring-data-mybatis-samples
can you show me more info about your exception?
i have two dependencies: 1) default spring mybatis starter
2) spring data mybatis starter
Without any additional configuration(only two mappers were created: TestMapper - standard mybatis mapper and another - spring data mybatis repository) i get exception:
TestMapper.class] required a single bean, but 2 were found:
Workaround: remove "spring data mybatis starter" dependency and configure Mybatis repositories manually...
don't add org.mybatis.spring.boot mybatis-spring-boot-starter 1.2.0 if you are using spring boot, you just need add this dependecy:
com.ifrabbit spring-boot-starter-data-mybatis 1.0.13.RELEASE
hmm but org.mybatis.spring.boot mybatis-spring-boot-starter 1.2.0 have additional possibilities to configure mybatis by spring boot way. why both approachs conflicts with each other? i suppose it would be better if com.ifrabbit spring-boot-starter-data-mybatis 1.0.13.RELEASE will use existing beans if they are configured...
maybe two SqlSessionFactories make this conflict.
pls show me you exception stackprint
I have already post usefull part of stacktrace: TestMapper.class] required a single bean, but 2 were found:
Another part of stacktrace contains only my classes info. As I can see there are two sqlSessionTemplate beans.
this reason hit the problem , when you use spring-boot-starter-data-mybatis , it will create a sqlsessiontemplate by atuoconfigration, so you should keep only one, and ignore another one.
I still think you don't need add org.mybatis.spring.boot mybatis-spring-boot-starter 1.2.0, can you explain the detail reason why you must add it to your project?
reasons to add org.mybatis.spring.boot mybatis-spring-boot-starter 1.2.0: 1)i can configure mybatis config without any code in application.yaml mybatis: type-aliases-package: mypackage configuration: map-underscore-to-camel-case: true default-fetch-size: 1000 default-statement-timeout: 300 ... As i know com.ifrabbit spring-boot-starter-data-mybatis doesn't have some of this configs. 2) my mappers will be picked up automatically(i need just add @Mapper annotation) ... Ofcourse i can do it manually without starter, and i can configure mybatis repositories manually without starter too. But i suppose main idea of spring boot starters is reducing java configuration. Usually i need some properties in application.yaml to configure whole library. And one more reason - as i know starters are designed to not conflict each other...(if you think problem is in org.mybatis.spring.boot mybatis-spring-boot-starter 1.2.0, can you explain me problem and i will write suggesstion in their repository)
My suggestion is: spring-boot-starter-data-mybatis should depend on mybatis-spring-boot-starter and use beans from there. I see same design for many other starters. For example spring-data-jpa depends on aop starter and jdbc starter. if you go by this way you will not need duplicate configuration of standard mybatis starter.
thanks for your suggestion. I will read source of mybatis-spring-boot-starter and decide next plan. This process will be as fast as possible.
when i try to use both starters spring-boot-starter-data-mybatis and mybatis-spring-boot-starter, i have an exception that two SqlSessionTemplate beans were created.