Changes in mybatis-spring-boot-starter 2.0

(Although it's a lot late ...) We've summarized the changes in 2.0 released on January 22, 2019: sweat_smile:

Note: Since 2.0.1 was released on April 2019, the content includes the changes of 2.0.1.

The main feature of this change is that it is the first version that requires Spring Boot 2.x (Spring Framework 5.x) or higher, as there are no major feature additions or improvements that will be the highlight of this change. (Although we have made some modest improvements ...).

In addition, it should be noted

Please also see if necessary.

Note: By the way, maintenance for Spring Boot 1.5.x (Spring Framework 4.3.x) is continuing in version 1.3.x, but it is announced that Spring Boot 1.5.x will be EOL by 2019/8. Since it has been done, the maintenance of version 1.3.x will be finished at the same time (= the maintenance will be finished by releasing 1.3.5 at the end).

Required version of dependent library

To use version 2.0, the following versions are required.

Required version of Java

Java 8 or above is required to use version 2.0.

Dependent library version update

In version 2.0, the following library versions have been updated.

Library name 1.3.Version 2 2.0.0 version 2.0.1 version
MyBatis 3.4.6 3.5.0 3.5.1
MyBatis Spring 1.3.2 2.0.0 2.0.1
Spring Boot 1.5.10.RELEASE 2.0.8.RELEASE 2.0.9.RELEASE

Note: Version 1.3.3 released at the same time as version 2.0.0 has been updated to Spring Boot 1.5.19.RELEASE, and version 1.3.4 released at the same time as version 2.0.1 has been updated to Spring Boot 1.5.20.

Supports specifying typeAliasesSuperType in configuration properties

typeAliasesSuperType is an option supported by SqlSessionFactoryBean provided by Spring MyBatis, and when scanning the class to be registered as a type alias from under the specified package, the class that can be assigned to the specified class interface (=) It is used when you want to scan only the inherited or implemented class).

For example ... If you want to register only the class that implements the com.example.data.Entity interface under the specified package in the type alias,

src/main/resources/application.properties


mybatis.type-aliases-package=com.example
mybatis.type-aliases-super-type=com.example.data.Entity

It can be realized by specifying.

Changed MyBatis Auto-Configure to be enabled only when there is only one injectable DataSource

Until version 1.3.x, if multiple DataSources are registered in the DI container without specifying the primary (= there are multiple DataSources of injection candidates with by type. (If it is), there was an error in MyBatis's Auto-Configure, but since 2.0, it has been changed so that MyBatis's Auto-Configure is disabled. This change provided feedback on behaviors such as Auto-Configure for JdbcTemplate provided by Spring Boot.

Regarding Auto-Configure support for multiple data sources, we would appreciate it if you could create an Issue as a function addition request (PR is also welcome!).

Applying spring-boot-autoconfigure-processor

[spring-boot-autoconfigure-processor](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html#boot-features- custom-starter-module-autoconfigure) reads the annotation information (meta information required for Auto-Configure) of the Auto-Configure class in advance at compile time and outputs it to the property file, so that Spring Boot This is an artifact that aims to speed up application startup time by eliminating the process of reading meta information from the class at runtime. Version 1.3.x did not use this mechanism, but since version 2.0, it has been improved to use this mechanism to output meta information to the property file.

Supports wildcards when specifying a base package

Starting with version 2.0.1, specify wildcards when specifying the base package to be scanned in the configuration properties (mybatis.type-aliases-package and mybatis.type-handlers-package). You will be able to.

In particular···

#Wildcard designation considering the depth of the package
mybatis.type-handlers-package=com.example.*.typehandler

#Wildcard specification without being aware of the depth of the package
mybatis.type-handlers-package=com.example.**.typehandler

It is possible to specify such a feeling.

Note: Since MyBatis itself does not support the specification of wildcards, you cannot specify wildcards in the base package specified in the configuration file (mybatis-config.xml) of MyBatis itself.

Important: ** When version 2.0.1 is applied, "[Duplicate error when scanning type alias](https://github.com/mybatis" (https://github.com/mybatis) / spring / issues / 362) ”has been reported, so you need to be careful when updating. ** Note that the error does not occur unconditionally, and it is known that if there is a class interface that satisfies the following conditions under the package to be scanned, a duplicate error will occur.

  • Using multiple anonymous objects
  • There are multiple interface classes / inner classes with the same name

This event will be fixed in MyBatis Spring 2.0.2 (scheduled to be released in early 2019/7), and version 2.1.0 incorporating MyBatis Spring 2.0.2 will be released in early 2019/7. I will. There are no plans to backport to version 2.0.x (because it was announced that Spring Boot 2.0.x will be EOL in March 2019 + because it is already out of GA). In order to solve this problem, it is basically recommended to update to version 2.1.x. However ... If you cannot update to version 2.1.x, please consider applying MyBatis Spring 2.0.2 individually.

It is no longer necessary to specify @ExtendWith (SpringExtension.class) when specifying @MybatisTest.

Starting with version 2.0.1, it is no longer necessary to specify @ExtendWith (SpringExtension.class) in the JUnit 5 test case class with @MybatisTest. This is an annotation specified by the JUnit 5 framework engine for the synthetic annotation @MybatisTest by adding@ExtendWith (SpringExtension.class)on the @ MybatisTest side. This is because it reads the information from. This change is feedback from the similar response to the @SpringBootTest provided by Spring Boot.

java:Version 2.0.Example of creating JUnit5 test case class in 1 or later


@MybatisTest
class MyMapperTest {
  // ...
}

java:Reference: Version 2.0.Example of creating JUnit5 test case class before 0


@ExtendWith(SpringExtension.class) //Version 2.0.This specification is not required after 1
@MybatisTest
class MyMapperTest {
  // ...
}

Recommended Posts

Changes in mybatis-spring-boot-starter 2.0
Changes in mybatis-spring-boot-starter 2.1
Changes in mybatis-spring-boot-starter 1.3
Changes in mybatis-spring-boot-starter 1.2
Changes in Mockito 2
Changes in Java 11
Changes in JUnit5M4-> M5
Core Location changes in iOS 14
Major changes in Spring Boot 1.5
Java version notation that changes in Java 10
Major changes in Spring Framework 5.0 core functionality