ORM
spring-boot
SpringBoot
MyBatis-Spring

MyBatis-SpringのMapper生成でハマった


MyBatisのMapper生成でハマった


現象

Mapperのinterfaceを定義しているのに、以下のエラーが発生する。

2018-11-21 22:08:22.200  WARN 5084 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[~.adapter.customer, ~.port.models]' package. Please check your configuration.

~~~

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-21 22:08:25.497 ERROR 5084 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field customerRecordMapper in ~.adapter.models.customer.CustomerRepositoryAdapter required a bean of type '~.adapter.models.customer.CustomerRecordMapper' that could not be found.

Action:

Consider defining a bean of type '~.adapter.models.customer.CustomerRecordMapper' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:51847', transport: 'socket'

Process finished with exit code 1


環境

Maven2で以下の依存


pom.xml

<dependency>

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>


原因

MapperをAutowiredしているクラスに以下のアノテーションがなかった。

@MapperScan(basePackages = { "jp.personal.gi.examazon.customerservice.model.adapter.models.customer"})

前作ったサンプルでは、なくても動いたはずなのに...

参考サイト