Changes in mybatis-spring-boot-starter 2.1

We have summarized the changes in 2.1 released on July 15, 2019. This change removes support for Spring Boot 2.0.x, which is already in EOL, and requires Spring Boot 2.1 or higher.

In addition, it should be noted

Please also see if necessary.

NOTE:

By the way, the maintenance of mybatis-spring-boot-starter 2.0.x is basically finished (we will consider whether to provide a patch when a fatal bug etc. is reported, but basically Will propose a version upgrade).

In addition, 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).

Since it has been reported that there is a bug in this version, it is necessary to apply a workaround if the conditions for causing the bug are met. The bug will be fixed in mybatis-spring-boot-starter 2.1.1 (mybtis-spring 2.0.3), which is scheduled to be released around mid-October 2019. (Added on July 21, 2019)

Required version of dependent library

Required version of Java

Dependent library version update

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

Library name 2.0.1 version 2.1.0 version Supplement
MyBatis 3.5.1 3.5.2 -
MyBatis Spring 2.0.1 2.0.2 As for API compatibility, MyBatis Spring 2.0+If so, it works, but2 to use all functions.0.2+Is necessary
MyBatis Velocity(Optional) - 2.1.0 API compatibility is 2.1.It works even before 0, but2 to use all functions.1.0+Is necessary
MyBatis Freemarker(Optional) - 1.2.0 API compatibility is 1.2.It works even before 0, but1 to use all functions.2.0+Is necessary
MyBatis Thymeleaf(Optional) - 1.0.1
Spring Boot 2.0.9.RELEASE 2.1.6.RELEASE 2 on Travis CI.2.0-Tested using SNAPSHOT

Automatic detection of Language Driver

Supported the mechanism to automatically detect LanguageDriver registered in DI container and apply it to MyBatis. With this support, the LanguageDriver class created by the developer can be applied to MyBatis by defining the Bean as follows.

Bean definition example of original Language Driver


@Bean
MyLanguageDriver myLanguageDriver() {
  return MyLanguageDriver();
}

Furthermore, if there is only one bean of LanguageDriver detected from the DI container, the detectedLanguageDriver will be treated as the default LanguageDriver class (if multiple beans are detected, the default settings of MyBatis itself will be used. A certain XMLLanguageDriver is applied as is). If you do not want to change the default LanguageDriver class by the automatic detection function, or if you want to change the default LanguageDriver class when using multiple LanguageDrivers together, the followingmybatis. Be sure to explicitly specify the defaultLanguageDriver class using the default-scripting-language-driver property (a property added in version 2.1).

Addition of mybatis.default-scripting-language-driver

Until version 2.0, as a way to specify the LanguageDriver class to be used by default, the property mybatis.configuration.default-scripting-language (property for setting the value directly to the configuration class provided by MyBatis itself) However, since it may not work as expected when combined with "Support for automatic configuration of LanguageDriver "described later, this property has been abolished (prohibited from use) and newly mybatis. Added .default-scripting-language-driver.

mybatis.default-scripting-language-driver={FQCN of the default LanguageDriver class}

Support for automatic configuration of Language Driver

Supports the automatic configuration mechanism for the following three submodules (LanguageDriver) that are genuine MyBatis.

If you add the jar files of the above three submodules to the classpath, the beans of the LanguageDriver class provided by the submodule will be automatically registered in the DI container and applied to MyBatis. If the developer explicitly defines the LanguageDriver class provided by the above submodule as a bean, automatic configuration will not be performed.

WARNING:

If all of the following conditions are met, backward compatibility will be lost and additional measures will be required.

  • Only one jar of the above three submodules (mybatis-velocity, mybatis-freemarker, mybatis-thymeleaf) ** is on the classpath **
  • The default LanguageDriver is not ** the LanguageDriver provided by the submodule **

If the conditions are met, the LanguageDriver class provided by the submodule is set to the defaultLanguageDriver, so it is necessary to explicitly specify the default LanguageDriver as shown below. There is.

mybatis.default-scripting-language-driver={FQCN of the default LanguageDriver class}

Using MyBatis Velocity

Add the following artifacts to apply ʻorg.mybatis.scripting.velocity.VelocityLanguageDriver (If you specify mybatis-velocity 2.0 or earlier, ʻorg.mybatis.scripting.velocity.Driver) to MyBatis.

pom.xml


<!--When using Mybatis Velocity-->
<dependency>
  <groupId>org.mybatis.scripting</groupId>
  <artifactId>mybatis-velocity</artifactId>
  <version>2.1.0</version>
</dependency>

When using mybatis-velocity 2.1.0 or later, you can customize the behavior of MyBatis Velocity and the Velocity template engine used in MyBatis Velocity by using the mechanism of configuration properties.

src/main/resources/application.properties


#
# mybatis.scripting-language-driver.velocity.{key} = {value}format
#

#Properties that customize the behavior of Velocity itself
# mybatis.scripting-language-driver.velocity.velocity-settings.{name} = {value}format
# {name}Please refer to the reference document for the properties that can be set to.
mybatis.scripting-language-driver.velocity.velocity-settings.runtime.custom_directives = com.example.directives.MyDirective

#Additional attributes to pass to the template engine(object)Property to specify
# mybatis.scripting-language-driver.velocity.additional-context-attributes.{name} = {value}
mybatis.scripting-language-driver.velocity.additional-context-attributes.likeEscape = com.example.helpers.LikeEscape

Use of MyBatis Free Marker

Add the following artifacts to apply ʻorg.mybatis.scripting.freemarker.FreeMarkerLanguageDriver` to MyBatis.

pom.xml


<dependency>
  <groupId>org.mybatis.scripting</groupId>
  <artifactId>mybatis-freemarker</artifactId>
  <version>1.2.0</version>
</dependency>

When using mybatis-velocity 1.2.0 or later, you can customize the behavior of the template engine of MyBatis FreeMarker and FreeMarker used in MyBatis FreeMarker by using the mechanism of the configuration property.

src/main/resources/application.properties


#
# mybatis.scripting-language-driver.freemarker.{key} = {value}format
#

#Properties that customize the behavior of FreeMarker itself
# mybatis.scripting-language-driver.freemarker.freemarker-settings.{name} = {value}format
# {name}Please refer to the reference document for the properties that can be set to.
mybatis.scripting-language-driver.freemarker.freemarker-settings.interpolation_syntax = dollar

#Properties that customize the behavior of MyBatis FreeMarker
# mybatis.scripting-language-driver.freemarker.{name} = {value}
# {name}Please refer to the reference document for the properties that can be set to.
mybatis.scripting-language-driver.freemarker.template-file.base-dir = sql

Use of MyBatis Thymeleaf

Add the following artifacts to apply ʻorg.mybatis.scripting.thymeleaf.ThymeleafLanguageDriver` to MyBatis.

pom.xml


<dependency>
  <groupId>org.mybatis.scripting</groupId>
  <artifactId>mybatis-thymeleaf</artifactId>
  <version>1.0.1</version>
</dependency>

You can customize the behavior of the Thymeleaf template engine used in MyBatis Thymeleaf and MyBatis Thymeleaf by using the mechanism of configuration properties.

src/main/resources/application.properties


#
# mybatis.scripting-language-driver.thymeleaf.{key} = {value}format
#

#Properties that customize the behavior of MyBatis Thymeleaf
# mybatis.scripting-language-driver.thymeleaf.{name} = {value}
# {name}Please refer to the reference document for the properties that can be set to.
mybatis.scripting-language-driver.thymeleaf.use2way = false
mybatis.scripting-language-driver.thymeleaf.template-file.cache-enabled = false
mybatis.scripting-language-driver.thymeleaf.dialect.like-additional-escape-target-chars = %, _

Mapper delay initialization control support

Added support for the option to control the initialization timing of Mapper registered in DI container (when DI container is initialized, injected or used). The default behavior is that all Mappers are initialized when the DI container is initialized.

This option causes an error when calling Mappr methods under certain conditions when enabling the bean deferred initialization mechanism supported by Spring Boot 2.2 (the official version has not been released at the time of posting). Therefore, it was added so that the user can control whether or not the delay initialization is applied to Mapper. If you just want to avoid the error, you can unconditionally disable the delayed initialization for Mapper, but I think that the delayed initialization mechanism is effective at the time of development (testing), so MyBatis (mybatis-spring) & mybatis-spring-boot-starter) Enabled to control the deferred initialization of Mapper independently. For more information, see About mybatis.lazy-initialization added in mybatis-spring-boot 2.1.0.

NOTE:

Since the delay initialization mechanism provided in this version is unique to MyBatis (mybatis-spring & mybatis-spring-boot-starter), it can also be used in Spring Boot 2.1 series.

Automatic detection of TypeHandler

Supported the mechanism to automatically detect TypeHandler registered in DI container and apply it to MyBatis. With this support, the TypeHandler class created by the developer can be applied to MyBatis by defining the Bean as follows.

Bean definition example of original TypeHandler


@Bean
MyTypeHandler myTypeHandler() {
  return MyTypeHandler();
}

Added MapperScannerConfigurer to the mapper scan disable condition

If the developer has explicitly defined Mapper to be registered in the DI container, mybatis-spring-boot-start will disable Mapper's automatic scanning. Until version 2.0, automatic scanning was disabled if any of the following conditions were met:

In version 2.1, in addition to the above

If you do, Mapper's automatic scanning will be disabled.

Fixed "Duplicate error when scanning type alias"

In mybatis-spring 2.0.1, which version 2.0.1 depends on, under certain conditions, "Duplicate error when scanning type aliases / kazuki43zoo / items / 38a24e051359e39c012c #% E3% 83% 99% E3% 83% BC% E3% 82% B9% E3% 83% 91% E3% 83% 83% E3% 82% B1% E3% 83% BC% E3% 82% B8% E6% 8C% 87% E5% AE% 9A% E6% 99% 82% E3% 81% AE% E3% 83% AF% E3% 82% A4% E3% 83% AB% E3% 83% 89% E3% 82% AB% E3% 83% BC% E3% 83% 89% E3% 82% 92% E3% 82% B5% E3% 83% 9D% E3% 83% BC% E3% 83% There was "88)", but it has been fixed in mybatis-spring 2.0.2, which version 2.1.0 depends on.

Added properties attribute to @MybatisTest

Added an attribute (properties) to specify properties (key = value format) to @MybatisTest. This support eliminates the need to use @TestPropertySource if you have a property that you want to apply only during testing. This support is a feedback of the mechanism added to @JdbcTest in Spring Boot 2.1 to @MybatisTest.

@MybatisTest(properties = {
  "logging.level.org.springframework.jdbc=debug",
  "spring.datasource.schema=classpath:TodoMapperTests/schema.sql"
  })
public class TodoMapperTests {
  // ...
}

Changed document source file from XDOC to Markdown

Changed the source file of the reference document generated using Maven Site Plugin from XDOC format to Markdown format. Since I just changed the format of the source file, the contents of the document are basically the same (except for the application part of the changes supported in 2.1.0), but ... "Code highlight of source code" is It's gone (I'm currently investigating whether it's a restriction when using Markdown or if the Plugin is used incorrectly).

With this support, the code highlight has disappeared from the post-build document, but by using Markdown format, the latest document (= snapshot version document) can be referenced via GitHub. (= I changed from XDOC format to Markdown format in order to give priority to this merit).

Add a simple sample

In version 2.1, we have increased the variation of Sample to enhance the integration test. It was.

Language Driver related

Sample project name Description
mybatis-spring-boot-sample-velocity MyBatis Velocity 2.1+Base simple sample project
mybatis-spring-boot-sample-velocity-legacy MyBatis Velocity 2.0-based simple sample project
mybatis-spring-boot-sample-freemarker MyBatis FreeMarker 1.2+Base simple sample project
mybatis-spring-boot-sample-velocity-legacy MyBatis FreeMarker 1.1.x-based simple sample project
mybatis-spring-boot-sample-thymeleaf Simple sample project of MyBatis Thymeleaf

JVM language related

Sample project name Description
mybatis-spring-boot-sample-groovy Simple sample project using Groovy
mybatis-spring-boot-sample-kotlin Simple sample project using Kotlin

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