Changes in mybatis-spring-boot-starter 1.2

We've summarized the 1.2 changes released on January 2, 2017.

In addition, it should be noted

Please see.

Note:

** 2017/4/10: Addendum ** Added changes in version 1.2.1.

** 2017/8/21: Addendum ** Added changes in version 1.2.2.

Required version of dependent library

To use version 1.2, the following versions are required.

Spring 4.3+ (Spring Boot 1.4+) required

In version 1.2, Spring Boot 1.4+, which is based on Spring 4.3, is required because it uses ʻObjectProvideradded from Spring 4.3 for automatic configuration. If you are using a wildcard (egmybatis.mapper-locations = classpath *: ** / mapper / *. Xml`) when reading the Mapper file, Spring Boot 1.4.3+ (Spring 4.3. If you do not use 5+), you may encounter a problem that Mapper files are read in duplicate (gh-108) ..

Note: When using on Spring 4.2 (Spring Boot 1.3), please use version 1.1.1.

Library version

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

Library name 1.1.1 version 1.2.0 version 1.2.1 version 1.2.Version 2
MyBatis 3.4.0 3.4.2 3.4.4 3.4.5
MyBatis Spring 1.3.0 1.3.1 1.3.1 1.3.1
Spring Boot 1.3.3.RELEASE 1.4.3.RELEASE 1.4.5.RELEASE 1.4.7.RELEASE

Relic dependency structure

In version 1.2, the dependency structure of mybatis-spring-boot-starter and mybatis-spring-boot-autoconfigure has been reviewed. This is in response to a comment from Stéphane Nicoll, one of the core committers of Spring Boot.

Specifically ... In version 1.1,

[INFO] +- org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:1.1.1:compile
[INFO] |  \- org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:jar:1.1.1:compile
[INFO] |     +- org.mybatis:mybatis:jar:3.4.0:compile
[INFO] |     +- org.mybatis:mybatis-spring:jar:1.3.0:compile
[INFO] |     +- org.springframework.boot:spring-boot:jar:1.4.3.RELEASE:compile
[INFO] |     |  \- org.springframework:spring-context:jar:4.3.5.RELEASE:compile
[INFO] |     |     +- org.springframework:spring-aop:jar:4.3.5.RELEASE:compile
[INFO] |     |     +- org.springframework:spring-beans:jar:4.3.5.RELEASE:compile
[INFO] |     |     \- org.springframework:spring-expression:jar:4.3.5.RELEASE:compile
[INFO] |     +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.3.RELEASE:compile
[INFO] |     \- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.3.RELEASE:compile
[INFO] |        +- org.springframework.boot:spring-boot-starter:jar:1.4.3.RELEASE:compile
[INFO] |        |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.3.RELEASE:compile
[INFO] |        |  |  +- ch.qos.logback:logback-classic:jar:1.1.8:compile
[INFO] |        |  |  |  \- ch.qos.logback:logback-core:jar:1.1.8:compile
[INFO] |        |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.22:compile
[INFO] |        |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.22:compile
[INFO] |        |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.22:compile
[INFO] |        |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |        +- org.apache.tomcat:tomcat-jdbc:jar:8.5.6:compile
[INFO] |        |  \- org.apache.tomcat:tomcat-juli:jar:8.5.6:compile
[INFO] |        \- org.springframework:spring-jdbc:jar:4.3.5.RELEASE:compile
[INFO] |           \- org.springframework:spring-tx:jar:4.3.5.RELEASE:compile

However, in version 1.2,

[INFO] +- org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:1.2.0:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.4.3.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-context:jar:4.3.5.RELEASE:compile
[INFO] |  |  |     +- org.springframework:spring-aop:jar:4.3.5.RELEASE:compile
[INFO] |  |  |     \- org.springframework:spring-expression:jar:4.3.5.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.3.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.8:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.8:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.22:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.22:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.22:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.6:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.6:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.5.RELEASE:compile
[INFO] |  |     +- org.springframework:spring-beans:jar:4.3.5.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-tx:jar:4.3.5.RELEASE:compile
[INFO] |  +- org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:jar:1.2.0:compile
[INFO] |  +- org.mybatis:mybatis:jar:3.4.2:compile
[INFO] |  \- org.mybatis:mybatis-spring:jar:1.3.1:compile

It has become. What has changed is ... In version 1.1, mybatis-spring-boot-starter depends only on mybatis-spring-boot-autoconfigure, and mybatis-spring-boot-autoconfigure is MyBatis, It had a dependency on MyBatis-Spring and Spring Boot. At first glance, it seems that there is no problem, but in effect mybatis-spring-boot-autoconfigure also plays the role of Starter, and this part is different from the idea of Starter and AutoConfigure provided by Spring Boot !! It was that.

This is ... If you add only the AutoConfigure artifact **, you should prevent the Spring Boot application from having side effects (make the autoconfiguration inactive) and enable autoconfiguration. Starter is the role to solve the dependent libraries required to do this in one shot! !! It seems like that.

Warning: If you specify mybatis-spring-boot-starter as the dependent artifact, you will not be affected by this change, but if you specify mybatis-spring-boot-autoconfigure , Please change to specify mybatis-spring-boot-starter when using version 1.2.

Add mybatis.configuration-properties

Starting with version 1.2, a new property (mybatis.configuration-properties) has been added to specify the value to replace with the placeholder ($ {key name} ). Placeholders can be used in MyBatis configuration files, Mapper XML files, SQL definition substitution variables, and some annotation values.

The format that can be specified in the property is

mybatis.configuration-properties.Key name=Key value

And ... for example

src/main/resources/application.properties


mybatis.configuration-properties.db.schema=prod

By defining as, you can refer to it like $ {db.schema}.

This is ... Expressed in the MyBatis configuration file,

mybatis-config.xml


<properties>
    <property name="db.schema" value="prod" />
</properties>

Expressed using ʻorg.mybatis.spring.SqlSessionFactoryBean` provided by MyBatis Spring,

@Bean
SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {
    SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    factoryBean.setDataSource(dataSource);
    Properties props = new Properties();
    props.setProperty("db.schema", "prod");
    factoryBean.setConfigurationProperties(props);
    return factoryBean;
}

or

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configurationProperties">
        <props>
            <prop key="db.schema">prod</prop> 
        </props>
    </property>
</bean>

Will be.

Note: Actually ... In version 1.1.1, the same thing can be achieved by defining as follows. This method can also be used in version 1.2, and if there is the same key name, the value specified in mybatis.configuration-properties added in version 1.2 takes precedence.

mybatis.configuration.variables.db.schema=prod

For example ... Define environment-independent values (or default values) in mybatis.configuration.variables and use mybatis.configuration-properties in the property file for each profile (for each environment). You can also use it to overwrite environment-dependent values.

Linking property keys under mybatis.configuration with IDE

From version 1.1, the property (mybatis.configuration. *) For configuring ʻorg.apache.ibatis.session.Configuration` is supported, but the property key is complemented on IDEs such as STS and IntelliJ IDEA. It was not targeted. This bug will be fixed in version 1.2.

Note: However ... this time there is another problem (gh-127) that the property key is duplicated ... This seems to be a bug in the maven-bundle-plugin used at build time and will be resolved in version 1.2.1.

** 2017/4/10: Addendum ** The duplicate property key issue has been resolved in version 1.2.1! !!

Addition of ConfigurationCustomizer interface

[Changes in version 1.3](http://qiita.com/kazuki43zoo/items/3f94d2049d331f81e6f5#configurationcustomizer%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%95%E3% 82% A7% E3% 83% BC% E3% 82% B9% E3% 81% AE% E8% BF% BD% E5% 8A% A0).

Addition of @MybatisTest (mybatis-spring-boot-starter-test)

Changes in version 1.3 Please refer to.

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