環境
- Windows10
- Eclipse 4.8
- SpringBoot 1.5.3
- Maven 3.5.4
- Mybatis3
Eclipseにて 実行→SpringBootアプリケーション
を実施したところ、
下記エラーが発生しました。
エラー抜粋
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in hoge.fuga.PiyoRepositoryImpl required a bean of type 'hoge.fuga.PiyoMapper' that could not be found.
Action:
Consider defining a bean of type 'hoge.fuga.PiyoMapper' in your configuration.
原因
Mapperが見つけられなかったようです。
@MapperScanでMapperを読み込ませるのを忘れていました。
対応
@MapperScanを定義しました。
@SpringBootApplication
@MapperScan(basePackages = "hoge.fuga") // ←Mapperクラスがあるpackageを設定
public class DemoApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(DemoApplication.class, args);
}
}
下記サイトの Mapperの自動検出
の項目にかかれているいずれかの対応が必要かと思います。
http://www.mybatis.org/spring/ja/mappers.html