0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SpringBoot】【トラブル】MyBatis経由でSQLが実行されているのかわからない問題の解決方法

Last updated at Posted at 2025-06-06

SpringBootで実装

こんにちは!私はSpringBootとMyBatisでの実装で色々手こずっている初心者です。今回はそんな私が直面した問題について共有します。

デバッグできなくてMyBatisのインタフェースからマッパーを呼び出しているのかわからない問題

MyBatisのマッパーはデバッグできません。なのでMyBatis経由で実際にクエリが実行されているのかが全く分かりません。

そんなわけでMyBatisを使うときはapprication.propertiesに以下の2行を追加しましょう

logging.level.com.example.demo.mapper=DEBUG
logging.file.name=app.log

こうすることでMyBatisのマッパー経由でのクエリをコンソールやログファイルで確認することができます。上のcom.example.demo.mapperの部分はmapperのインタフェースがあるパッケージ名を指定しましょう。

MyBatisのMapperのXMLはコンパイル時にmapperパッケージにあると読み込まれないことから以下の設定をapprication.propertiesに追記して【プロジェクト名】/src/min/resourcesの下のmapperディレクトリに集約しましょう

mybatis.mapper-locations=classpath*:/mapper/*.xml

image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?