LoginSignup
6

More than 5 years have passed since last update.

mybatis-spring-boot-starter 1.1の変更点

Last updated at Posted at 2016-04-19

2016年4月19日のリリースされた1.1(1.1.1)の変更点をまとめました。
なお、mybatis-spring-boot-starterの使い方については、こちらをご覧下さい。

依存ライブラリの必須バージョン

mybatis 3.4+、mybatis-spring 1.3+が必須です。

Mapperインタフェースのスキャン対象

バージョン1.0系では、Spring Bootアプリケーション(@SpringBootApplicationを付与したクラス)が格納されているパッケージ配下に格納されているインタフェースが全てMapperインタフェースとしてスキャンされていました。この仕組みは便利な反面で、意図していないインターフェースがMapperインタフェースとしてスキャンされてDIコンテナに登録されてしまうという問題がありました。
バージョン1.1系では、Spring Bootアプリケーション(@SpringBootApplicationを付与したクラス)が格納されているパッケージ配下に格納されているインターフェースのうち、@rg.apache.ibatis.annotations.Mapper(mybatis 3.4で追加されたアノテーション)が付与されたインタフェースをMapperインターフェースとしてスキャンします。

Note:
バージョン1.0系と同じ動作にしたい場合は、@MapperScanを使用してスキャンするパッケージを明示的に指定してください。

src/main/java/com/example/MybatisDemoApplication.java
package com.example;
// ...
@MapperScan("com.example") // スキャンするベースパッケージを明示的に指定する
@SpringBootApplication
public class MybatisDemoApplication {
    // ...
}

application.propertiesを使用したMyBatisの設定

バージョン1.0系では、MyBatis自体の動作を変更する場合は、MyBatis設定ファイルの<settings>タグ内に設定を指定する必要がありました。バージョン1.1系では、MyBatis設定ファイルを使わずにapplication.propertiesの中に設定を指定することができます。

src/main/resources/applicaion.properties
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=30

は、

src/main/resources/applicaion.properties
mybatis.config-location=classpath:/mybatis/mybatis-config.xml
src/main/resources/mybatis/mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true" />
        <setting name="defaultFetchSize" value="100" />
        <setting name="defaultStatementTimeout" value="30" />
    </settings>
</configuration>

と同義です。

Note:
バージョン1.1.1では、残念ながらIDE上でmybatis.configuration配下のプロパティが補完されません。これは、https://github.com/mybatis/spring-boot-starter/pull/61 がマージされると解決されます。 これは、バージョン1.2(2017/1/2リリース)で解決されました。 :smile:

MyBatis設定ファイルのプロパティキー

バージョン1.0系では、mybatis.configでしたが、バージョン1.1系では、mybatis.config-locationになりました。

  • 1.1系の指定例
src/main/resources/applicaion.properties
mybatis.config-location=classpath:/mybatis/mybatis-config.xml
  • 1.0系の指定例(1.1系では非推奨)
src/main/resources/applicaion.properties
mybatis.config=classpath:/mybatis/mybatis-config.xml

mybatis.executor-typeのデフォルト値

バージョン1.0系では、SIMPLE固定でしたが、バージョン1.1系では、MyBatis設定の設定値(デフォルト値はSIMPLE)が適用されます。

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
6