Skip to content
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

Support @MockBean for a MyBatis mapper interface #475

Closed
dldiehl77 opened this issue Jul 11, 2020 · 2 comments
Closed

Support @MockBean for a MyBatis mapper interface #475

dldiehl77 opened this issue Jul 11, 2020 · 2 comments
Assignees
Milestone

Comments

@dldiehl77
Copy link

I am using MyBatis Spring Boot Starter version 2.1.3. Ever since moving to Spring Boot 2.2.7 (I've also tried 2.2.8 and 2.3.1 with the same results), I've had a problem using the MockBean annotation to mock a MyBatis interface (e.g. DAO or Mapper).

I have a MyBatis interface annotated with both Mapper and Repository. When I try to use the Spring Boot MockBean annotation, the object that is injected into my Service classes and the object that is injected into my unit test class are not the same, making it so that I cannot use Mockito.verify (as an example of one issue this causes).

A complete description is on stackoverflow here: https://stackoverflow.com/questions/62409666/mockbean-and-mybatis-mapper-not-working-together-as-they-did-before-spring-boot

Including a demo of the issue here: github.com/dldiehl77/mybatis-issues/tree/master/so-62409666

@harawata
Copy link
Member

Thank you very much, @dldiehl77 !

This is a side effect of the fix for spring-projects/spring-boot#20665 .
The solution is to add FactoryBean.OBJECT_TYPE_ATTRIBUTE [1] attribute to mapper beans, it seems.

@kazuki43zoo ,
I opened a PR mybatis/spring#494 on mybatis-spring, but does it make more sense to do it in mybatis-spring-boot-starter? (I wasn't sure if that's possible)

Thanks in advance!

[1] spring-projects/spring-boot@f4985ab

@harawata harawata self-assigned this Nov 8, 2020
@harawata harawata added this to the 2.1.4 milestone Nov 8, 2020
@harawata
Copy link
Member

harawata commented Nov 8, 2020

Hello @dldiehl77 !

We have merged mybatis/spring#494 .
You should be able to verify the fix using the latest 2.1.4-SNAPSHOT.
Thank you again for your contribution!

@harawata harawata closed this as completed Nov 8, 2020
@kazuki43zoo kazuki43zoo changed the title Problem using a Mockito mock on a MyBatis (Mapper annotated) interface. Support @MockBean for a MyBatis interface. Nov 9, 2020
@kazuki43zoo kazuki43zoo changed the title Support @MockBean for a MyBatis interface. Support @MockBean for a MyBatis interface Nov 9, 2020
@kazuki43zoo kazuki43zoo changed the title Support @MockBean for a MyBatis interface Support @MockBean for a MyBatis mapper interface Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants