LoginSignup
4
3

More than 5 years have passed since last update.

SpringBoot + Mybatis 起動時にエラー

Posted at

環境

  • 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

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3