-要和Spring一起使用MyBatis,需要在Spring应用上下文中定义至少两样东西:一个SqlSessionFactory和至少一个数据映射器类。
+ 要和 Spring 一起使用 MyBatis,需要在 Spring 应用上下文中定义至少两样东西:一个 SqlSessionFactory 和至少一个数据映射器类。
-在MyBatis-Spring中,可使用SqlSessionFactoryBean来创建SqlSessionFactory。要配置这个工厂bean,只需要把下面代码放在Spring的XML配置文件中:
+ 在 MyBatis-Spring 中,可使用 SqlSessionFactoryBean来创建 SqlSessionFactory。
+ 要配置这个工厂 bean,只需要把下面代码放在 Spring 的 XML 配置文件中:
-需要注意的是:SqlSessionFactory需要一个DataSource(数据源,译者注)。这可以是任意的DataSource,配置它就和配置其它Spring数据库连接一样。
+ 注意:SqlSessionFactory 需要一个 DataSource(数据源,译者注)。
+ 这可以是任意的 DataSource,只需要和配置其它 Spring 数据库连接一样配置它就可以了。
-假设你定义了一个如下的mapper接口:
+ 假设你定义了一个如下的 mapper 接口:
-那么可以通过MapperFactoryBean像下面那样把接口加入到Spring中:
+ 那么可以通过 MapperFactoryBean 将接口加入到 Spring 中:
]]>
-需要注意的是:所指定的映射器类必须是一个接口,而不是具体的实现类。在这个示例中通过注解来指定SQL语句,但是通过MyBatis映射器的XML文件也行。
+ 需要注意的是:所指定的映射器类必须是一个接口,而不是具体的实现类。在这个示例中,通过注解来指定 SQL 语句,但是也可以使用 MyBatis mapper 的 XML 配置文件。
-一旦完成配置,你可以像其它Spring中的bean注入方法将映射器到业务(bussiness)或服务(service)对象中。MapperFactoryBean用来处理SqlSession的创建和关闭动作。
-如果使用了Spring的事务,那么当事务完成时,session将会被提交或回滚。最终任何异常都会被翻译成Spring的DataAccessException异常。
+ 配置好之后,你就可以像 Spring 中普通的 bean 注入方法那样,将 mapper 注入到你的业务(bussiness)或服务(service)对象中。
+ MapperFactoryBean 将会负责 SqlSession 的创建和关闭。
+ 如果使用了 Spring 的事务功能,那么当事务完成时,session 将会被提交或回滚。最终任何异常都会被转换成 Spring 的 DataAccessException 异常。
What's happening is that first the insertInteractionMetadata will be called, and the update
- statement is configured to return the ids created by the jdbc driver (keyProperty and keyColumn).
- As the InteractionMetadata object were updated by this query the next query can be used to write the parent
- object Interaction via insertInteraction.
+
However note that JDBC drivers don't behave the same in this regard. At the time of this writing
- the H2 driver 1.3.168 will only return the latest index even in BATCH mode (see org.h2.jdbc.JdbcStatement#getGeneratedKeys),
- while the MySQL JDBC driver will behave as expected and return all the IDs.
+
+ * By default implementation, an item does not convert.
+ *
+ * @param itemToParameterConverter a converter that converting item to parameter object
+ * @since 2.0.0
+ */
+ public void setItemToParameterConverter(Converter itemToParameterConverter) {
+ this.itemToParameterConverter = itemToParameterConverter;
+ }
+
/**
* Check mandatory properties - there must be an SqlSession and a statementId.
*/
@@ -110,6 +125,7 @@ public void afterPropertiesSet() {
notNull(sqlSessionTemplate, "A SqlSessionFactory or a SqlSessionTemplate is required.");
isTrue(ExecutorType.BATCH == sqlSessionTemplate.getExecutorType(), "SqlSessionTemplate's executor type must be BATCH");
notNull(statementId, "A statementId is required.");
+ notNull(itemToParameterConverter, "A itemToParameterConverter is required.");
}
/**
@@ -122,7 +138,7 @@ public void write(final List extends T> items) {
LOGGER.debug(() -> "Executing batch with " + items.size() + " items.");
for (T item : items) {
- sqlSessionTemplate.update(statementId, item);
+ sqlSessionTemplate.update(statementId, itemToParameterConverter.convert(item));
}
List results = sqlSessionTemplate.flushStatements();
@@ -146,4 +162,13 @@ public void write(final List extends T> items) {
}
}
+ private static class PassThroughConverter implements Converter {
+
+ @Override
+ public T convert(T source) {
+ return source;
+ }
+
+ }
+
}
diff --git a/src/main/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilder.java b/src/main/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilder.java
index 3b52fffa4d..856ef0a15d 100644
--- a/src/main/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilder.java
+++ b/src/main/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilder.java
@@ -18,6 +18,7 @@
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.batch.MyBatisBatchItemWriter;
+import org.springframework.core.convert.converter.Converter;
/**
* A builder for the {@link MyBatisBatchItemWriter}.
@@ -32,6 +33,7 @@ public class MyBatisBatchItemWriterBuilder {
private SqlSessionFactory sqlSessionFactory;
private String statementId;
private Boolean assertUpdates;
+ private Converter itemToParameterConverter;
/**
* Set the {@link SqlSessionTemplate} to be used by writer for database access.
@@ -83,6 +85,18 @@ public MyBatisBatchItemWriterBuilder assertUpdates(boolean assertUpdates) {
return this;
}
+ /**
+ * Set a converter that converting item to parameter object.
+ *
+ * @param itemToParameterConverter a converter that converting item to parameter object
+ * @return this instance for method chaining
+ * @see MyBatisBatchItemWriter#setItemToParameterConverter(Converter)
+ */
+ public MyBatisBatchItemWriterBuilder itemToParameterConverter(Converter itemToParameterConverter) {
+ this.itemToParameterConverter = itemToParameterConverter;
+ return this;
+ }
+
/**
* Returns a fully built {@link MyBatisBatchItemWriter}.
*
@@ -96,6 +110,9 @@ public MyBatisBatchItemWriter build() {
if (this.assertUpdates != null) {
writer.setAssertUpdates(this.assertUpdates);
}
+ if (this.itemToParameterConverter != null) {
+ writer.setItemToParameterConverter(this.itemToParameterConverter);
+ }
return writer;
}
diff --git a/src/test/java/org/mybatis/spring/batch/MyBatisBatchItemWriterTest.java b/src/test/java/org/mybatis/spring/batch/MyBatisBatchItemWriterTest.java
index 3bec43b3fa..7a3563b7d0 100644
--- a/src/test/java/org/mybatis/spring/batch/MyBatisBatchItemWriterTest.java
+++ b/src/test/java/org/mybatis/spring/batch/MyBatisBatchItemWriterTest.java
@@ -16,20 +16,28 @@
package org.mybatis.spring.batch;
import org.apache.ibatis.executor.BatchResult;
+import org.apache.ibatis.session.ExecutorType;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.batch.domain.Employee;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
+import java.time.Clock;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.*;
@@ -77,4 +85,50 @@ void testZeroUpdateCountShouldThrowException() {
);
}
+ @Test
+ void testItemToParameterConverterIsDefault() {
+ this.writer.setAssertUpdates(false);
+ this.writer.setStatementId("updateEmployee");
+
+ Employee employee = new Employee();
+ List employees = Collections.singletonList(employee);
+ writer.write(employees);
+
+ Mockito.verify(this.mockSqlSessionTemplate).update("updateEmployee", employee);
+ }
+
+ @Test
+ void testSetItemToParameterConverter() {
+ this.writer.setAssertUpdates(false);
+ this.writer.setStatementId("updateEmployee");
+ this.writer.setItemToParameterConverter(item -> {
+ Map parameter = new HashMap<>();
+ parameter.put("item", item);
+ parameter.put("now",
+ LocalDateTime.now(Clock.fixed(Instant.ofEpochMilli(0), ZoneId.systemDefault())));
+ return parameter;
+ });
+
+ Employee employee = new Employee();
+ List employees = Collections.singletonList(employee);
+ writer.write(employees);
+
+ Map parameter = new HashMap<>();
+ parameter.put("item", employee);
+ parameter.put("now",
+ LocalDateTime.now(Clock.fixed(Instant.ofEpochMilli(0), ZoneId.systemDefault())));
+ Mockito.verify(this.mockSqlSessionTemplate).update("updateEmployee", parameter);
+ }
+
+ @Test
+ void testItemToParameterConverterIsNull() {
+ given(mockSqlSessionTemplate.getExecutorType()).willReturn(ExecutorType.BATCH);
+ this.writer.setStatementId("updateEmployee");
+ writer.setItemToParameterConverter(null);
+
+ assertThrows(IllegalArgumentException.class, () -> writer.afterPropertiesSet(),
+ "A itemToParameterConverter is required.");
+
+ }
+
}
diff --git a/src/test/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilderTest.java b/src/test/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilderTest.java
index 5fedb5fcbe..bb92161cea 100644
--- a/src/test/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilderTest.java
+++ b/src/test/java/org/mybatis/spring/batch/builder/MyBatisBatchItemWriterBuilderTest.java
@@ -31,9 +31,11 @@
import org.mybatis.spring.batch.MyBatisBatchItemWriter;
import javax.sql.DataSource;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.time.Clock;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.*;
/**
* Tests for {@link MyBatisBatchItemWriterBuilder}.
@@ -137,6 +139,38 @@ void testConfigurationAssertUpdatesIsFalse() {
}
+ @Test
+ void testConfigurationSetItemToParameterConverter() {
+
+ // @formatter:off
+ MyBatisBatchItemWriter itemWriter = new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(this.sqlSessionFactory)
+ .statementId("updateFoo")
+ .itemToParameterConverter(item -> {
+ Map parameter = new HashMap<>();
+ parameter.put("item", item);
+ parameter.put("now", LocalDateTime.now(Clock.fixed(Instant.ofEpochMilli(0), ZoneId.systemDefault())));
+ return parameter;
+ })
+ .build();
+ // @formatter:on
+ itemWriter.afterPropertiesSet();
+
+ List foos = getFoos();
+
+ itemWriter.write(foos);
+
+ Map parameter = new HashMap<>();
+ parameter.put("now",
+ LocalDateTime.now(Clock.fixed(Instant.ofEpochMilli(0), ZoneId.systemDefault())));
+ parameter.put("item", foos.get(0));
+ Mockito.verify(this.sqlSession).update("updateFoo", parameter);
+ parameter.put("item", foos.get(1));
+ Mockito.verify(this.sqlSession).update("updateFoo", parameter);
+ parameter.put("item", foos.get(2));
+ Mockito.verify(this.sqlSession).update("updateFoo", parameter);
+ }
+
private List getFoos() {
return Arrays.asList(new Foo("foo1"), new Foo("foo2"), new Foo("foo3"));
}
From df2602e22e5fbd75d116ce6ace7a94846feb0c43 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Fri, 4 May 2018 13:13:00 +0900
Subject: [PATCH 027/933] Fix javadoc errors and warnings
---
.../mybatis/spring/SqlSessionFactoryBean.java | 36 ++++++++++++++++---
.../org/mybatis/spring/SqlSessionHolder.java | 3 +-
.../mybatis/spring/SqlSessionTemplate.java | 18 +++++-----
.../org/mybatis/spring/SqlSessionUtils.java | 7 ++--
.../mybatis/spring/annotation/MapperScan.java | 22 ++++++++++--
.../spring/batch/MyBatisBatchItemWriter.java | 18 +++++-----
.../spring/mapper/MapperFactoryBean.java | 8 ++---
.../mapper/MapperScannerConfigurer.java | 15 ++++----
.../spring/support/SqlSessionDaoSupport.java | 10 +++++-
9 files changed, 95 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
index 61c560ebdf..35f3af777f 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,7 +125,7 @@ public class SqlSessionFactoryBean implements FactoryBean, In
* Sets the ObjectFactory.
*
* @since 1.1.2
- * @param objectFactory
+ * @param objectFactory a custom ObjectFactory
*/
public void setObjectFactory(ObjectFactory objectFactory) {
this.objectFactory = objectFactory;
@@ -135,7 +135,7 @@ public void setObjectFactory(ObjectFactory objectFactory) {
* Sets the ObjectWrapperFactory.
*
* @since 1.1.2
- * @param objectWrapperFactory
+ * @param objectWrapperFactory a specified ObjectWrapperFactory
*/
public void setObjectWrapperFactory(ObjectWrapperFactory objectWrapperFactory) {
this.objectWrapperFactory = objectWrapperFactory;
@@ -145,7 +145,7 @@ public void setObjectWrapperFactory(ObjectWrapperFactory objectWrapperFactory) {
* Gets the DatabaseIdProvider
*
* @since 1.1.0
- * @return
+ * @return a specified DatabaseIdProvider
*/
public DatabaseIdProvider getDatabaseIdProvider() {
return databaseIdProvider;
@@ -156,24 +156,40 @@ public DatabaseIdProvider getDatabaseIdProvider() {
* As of version 1.2.2 this variable is not initialized by default.
*
* @since 1.1.0
- * @param databaseIdProvider
+ * @param databaseIdProvider a DatabaseIdProvider
*/
public void setDatabaseIdProvider(DatabaseIdProvider databaseIdProvider) {
this.databaseIdProvider = databaseIdProvider;
}
+ /**
+ * Gets the VFS.
+ * @return a specified VFS
+ */
public Class extends VFS> getVfs() {
return this.vfs;
}
+ /**
+ * Sets the VFS.
+ * @param vfs a VFS
+ */
public void setVfs(Class extends VFS> vfs) {
this.vfs = vfs;
}
+ /**
+ * Gets the Cache.
+ * @return a specified Cache
+ */
public Cache getCache() {
return this.cache;
}
+ /**
+ * Sets the Cache.
+ * @param cache a Cache
+ */
public void setCache(Cache cache) {
this.cache = cache;
}
@@ -265,6 +281,8 @@ public void setFailFast(boolean failFast) {
/**
* Set the location of the MyBatis {@code SqlSessionFactory} config file. A typical value is
* "WEB-INF/mybatis-configuration.xml".
+ *
+ * @param configLocation a location the MyBatis config file
*/
public void setConfigLocation(Resource configLocation) {
this.configLocation = configLocation;
@@ -286,6 +304,8 @@ public void setConfiguration(Configuration configuration) {
* This is an alternative to specifying "<sqlmapper>" entries in an MyBatis config file.
* This property being based on Spring's resource abstraction also allows for specifying
* resource patterns here: e.g. "classpath*:sqlmap/*-mapper.xml".
+ *
+ * @param mapperLocations location of MyBatis mapper files
*/
public void setMapperLocations(Resource[] mapperLocations) {
this.mapperLocations = mapperLocations;
@@ -295,6 +315,8 @@ public void setMapperLocations(Resource[] mapperLocations) {
* Set optional properties to be passed into the SqlSession configuration, as alternative to a
* {@code <properties>} tag in the configuration xml file. This will be used to
* resolve placeholders in the config file.
+ *
+ * @param sqlSessionFactoryProperties optional properties for the SqlSessionFactory
*/
public void setConfigurationProperties(Properties sqlSessionFactoryProperties) {
this.configurationProperties = sqlSessionFactoryProperties;
@@ -314,6 +336,8 @@ public void setConfigurationProperties(Properties sqlSessionFactoryProperties) {
* underlying target {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy}
* passed in, it will be unwrapped to extract its target {@code DataSource}.
*
+ * @param dataSource a JDBC {@code DataSource}
+ *
*/
public void setDataSource(DataSource dataSource) {
if (dataSource instanceof TransactionAwareDataSourceProxy) {
@@ -333,6 +357,8 @@ public void setDataSource(DataSource dataSource) {
* This is mainly meant for testing so that mock SqlSessionFactory classes can be injected. By
* default, {@code SqlSessionFactoryBuilder} creates {@code DefaultSqlSessionFactory} instances.
*
+ * @param sqlSessionFactoryBuilder a SqlSessionFactoryBuilder
+ *
*/
public void setSqlSessionFactoryBuilder(SqlSessionFactoryBuilder sqlSessionFactoryBuilder) {
this.sqlSessionFactoryBuilder = sqlSessionFactoryBuilder;
diff --git a/src/main/java/org/mybatis/spring/SqlSessionHolder.java b/src/main/java/org/mybatis/spring/SqlSessionHolder.java
index e4ced13a80..d55309b4e8 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionHolder.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionHolder.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2016 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ public final class SqlSessionHolder extends ResourceHolderSupport {
*
* @param sqlSession the {@code SqlSession} has to be hold.
* @param executorType the {@code ExecutorType} has to be hold.
+ * @param exceptionTranslator the {@code PersistenceExceptionTranslator} has to be hold.
*/
public SqlSessionHolder(SqlSession sqlSession,
ExecutorType executorType,
diff --git a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java
index 5933b21701..959aa9aaeb 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -88,7 +88,7 @@ public class SqlSessionTemplate implements SqlSession, DisposableBean {
* Constructs a Spring managed SqlSession with the {@code SqlSessionFactory}
* provided as an argument.
*
- * @param sqlSessionFactory
+ * @param sqlSessionFactory a factory of SqlSession
*/
public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
this(sqlSessionFactory, sqlSessionFactory.getConfiguration().getDefaultExecutorType());
@@ -100,8 +100,8 @@ public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
* {@code ExecutorType} cannot be changed once the {@code SqlSessionTemplate}
* is constructed.
*
- * @param sqlSessionFactory
- * @param executorType
+ * @param sqlSessionFactory a factory of SqlSession
+ * @param executorType an executor type on session
*/
public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType) {
this(sqlSessionFactory, executorType,
@@ -119,9 +119,9 @@ public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType exec
* exception translation will be done and MyBatis exceptions will be
* thrown
*
- * @param sqlSessionFactory
- * @param executorType
- * @param exceptionTranslator
+ * @param sqlSessionFactory a factory of SqlSession
+ * @param executorType an executor type on session
+ * @param exceptionTranslator a translator of exception
*/
public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory, ExecutorType executorType,
PersistenceExceptionTranslator exceptionTranslator) {
@@ -408,8 +408,8 @@ public List flushStatements() {
* The implementation of {@link DisposableBean} forces spring context to use {@link DisposableBean#destroy()} method instead of {@link SqlSessionTemplate#close()} to shutdown gently.
*
* @see SqlSessionTemplate#close()
- * @see org.springframework.beans.factory.support.DisposableBeanAdapter#inferDestroyMethodIfNecessary
- * @see org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME
+ * @see "org.springframework.beans.factory.support.DisposableBeanAdapter#inferDestroyMethodIfNecessary(Object, RootBeanDefinition)"
+ * @see "org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME"
*/
@Override
public void destroy() throws Exception {
diff --git a/src/main/java/org/mybatis/spring/SqlSessionUtils.java b/src/main/java/org/mybatis/spring/SqlSessionUtils.java
index 11a2262bf4..fe155ccd45 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionUtils.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionUtils.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,6 +77,7 @@ public static SqlSession getSqlSession(SqlSessionFactory sessionFactory) {
* @param sessionFactory a MyBatis {@code SqlSessionFactory} to create new sessions
* @param executorType The executor type of the SqlSession to create
* @param exceptionTranslator Optional. Translates SqlSession.commit() exceptions to Spring exceptions.
+ * @return an SqlSession managed by Spring Transaction Manager
* @throws TransientDataAccessResourceException if a transaction is active and the
* {@code SqlSessionFactory} is not using a {@code SpringManagedTransactionFactory}
* @see SpringManagedTransactionFactory
@@ -162,8 +163,8 @@ private static SqlSession sessionHolder(ExecutorType executorType, SqlSessionHol
* If it is not, it closes it, otherwise it just updates the reference counter and
* lets Spring call the close callback when the managed transaction ends
*
- * @param session
- * @param sessionFactory
+ * @param session a target SqlSession
+ * @param sessionFactory a factory of SqlSession
*/
public static void closeSqlSession(SqlSession session, SqlSessionFactory sessionFactory) {
notNull(session, NO_SQL_SESSION_SPECIFIED);
diff --git a/src/main/java/org/mybatis/spring/annotation/MapperScan.java b/src/main/java/org/mybatis/spring/annotation/MapperScan.java
index 71401d1c08..7fa9b36777 100644
--- a/src/main/java/org/mybatis/spring/annotation/MapperScan.java
+++ b/src/main/java/org/mybatis/spring/annotation/MapperScan.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,8 +77,9 @@
/**
* Alias for the {@link #basePackages()} attribute. Allows for more concise
* annotation declarations e.g.:
- * {@code @EnableMyBatisMapperScanner("org.my.pkg")} instead of {@code
- * @EnableMyBatisMapperScanner(basePackages= "org.my.pkg"})}.
+ * {@code @MapperScan("org.my.pkg")} instead of {@code @MapperScan(basePackages = "org.my.pkg"})}.
+ *
+ * @return base package names
*/
String[] value() default {};
@@ -86,6 +87,8 @@
* Base packages to scan for MyBatis interfaces. Note that only interfaces
* with at least one method will be registered; concrete classes will be
* ignored.
+ *
+ * @return base package names for scanning mapper interface
*/
String[] basePackages() default {};
@@ -94,12 +97,16 @@
* to scan for annotated components. The package of each class specified will be scanned.
*
Consider creating a special no-op marker class or interface in each package
* that serves no purpose other than being referenced by this attribute.
+ *
+ * @return classes that indicate base package for scanning mapper interface
*/
Class>[] basePackageClasses() default {};
/**
* The {@link BeanNameGenerator} class to be used for naming detected components
* within the Spring container.
+ *
+ * @return the class of {@link BeanNameGenerator}
*/
Class extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;
@@ -110,6 +117,8 @@
* the specified annotation.
*
* Note this can be combined with markerInterface.
+ *
+ * @return the annotation that the scanner will search for
*/
Class extends Annotation> annotationClass() default Annotation.class;
@@ -120,6 +129,8 @@
* the specified interface class as a parent.
*
* Note this can be combined with annotationClass.
+ *
+ * @return the parent that the scanner will search for
*/
Class> markerInterface() default Class.class;
@@ -127,6 +138,8 @@
* Specifies which {@code SqlSessionTemplate} to use in the case that there is
* more than one in the spring context. Usually this is only needed when you
* have more than one datasource.
+ *
+ * @return the bean name of {@code SqlSessionTemplate}
*/
String sqlSessionTemplateRef() default "";
@@ -134,12 +147,15 @@
* Specifies which {@code SqlSessionFactory} to use in the case that there is
* more than one in the spring context. Usually this is only needed when you
* have more than one datasource.
+ *
+ * @return the bean name of {@code SqlSessionFactory}
*/
String sqlSessionFactoryRef() default "";
/**
* Specifies a custom MapperFactoryBean to return a mybatis proxy as spring bean.
*
+ * @return the class of {@code MapperFactoryBean}
*/
Class extends MapperFactoryBean> factoryBean() default MapperFactoryBean.class;
diff --git a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
index da8f6144df..eab5581048 100644
--- a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
+++ b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,16 +36,16 @@
/**
* {@code ItemWriter} that uses the batching features from
* {@code SqlSessionTemplate} to execute a batch of statements for all items
- * provided.
- *
- * Provided to facilitate the migration from Spring-Batch iBATIS 2 writers to MyBatis 3
- *
+ * provided.
+ *
+ * Provided to facilitate the migration from Spring-Batch iBATIS 2 writers to MyBatis 3.
+ *
* The user must provide a MyBatis statement id that points to the SQL statement defined
- * in the MyBatis.
- *
+ * in the MyBatis.
+ *
* It is expected that {@link #write(List)} is called inside a transaction. If it is not
- * each statement call will be autocommitted and flushStatements will return no results.
- *
+ * each statement call will be autocommitted and flushStatements will return no results.
+ *
* The writer is thread safe after its properties are set (normal singleton
* behavior), so it can be used to write in multiple concurrent transactions.
*
diff --git a/src/main/java/org/mybatis/spring/mapper/MapperFactoryBean.java b/src/main/java/org/mybatis/spring/mapper/MapperFactoryBean.java
index 13ba830efe..df938f745f 100644
--- a/src/main/java/org/mybatis/spring/mapper/MapperFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/mapper/MapperFactoryBean.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -134,13 +134,13 @@ public Class getMapperInterface() {
/**
* If addToConfig is false the mapper will not be added to MyBatis. This means
* it must have been included in mybatis-config.xml.
- *
+ *
* If it is true, the mapper will be added to MyBatis in the case it is not already
* registered.
- *
+ *
* By default addToConfig is true.
*
- * @param addToConfig
+ * @param addToConfig a flag that whether add mapper to MyBatis or not
*/
public void setAddToConfig(boolean addToConfig) {
this.addToConfig = addToConfig;
diff --git a/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java b/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java
index 8ac71883e8..97370c3b6c 100644
--- a/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java
+++ b/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,7 +73,6 @@
* and bean name properties all support ${property} style substitution.
*
* Configuration sample:
- *
*
*
* {@code
@@ -133,7 +132,7 @@ public void setBasePackage(String basePackage) {
/**
* Same as {@code MapperFactoryBean#setAddToConfig(boolean)}.
*
- * @param addToConfig
+ * @param addToConfig a flag that whether add mapper to MyBatis or not
* @see MapperFactoryBean#setAddToConfig(boolean)
*/
public void setAddToConfig(boolean addToConfig) {
@@ -175,7 +174,7 @@ public void setMarkerInterface(Class> superClass) {
*
* @deprecated Use {@link #setSqlSessionTemplateBeanName(String)} instead
*
- * @param sqlSessionTemplate
+ * @param sqlSessionTemplate a template of SqlSession
*/
@Deprecated
public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
@@ -206,7 +205,7 @@ public void setSqlSessionTemplateBeanName(String sqlSessionTemplateName) {
*
* @deprecated Use {@link #setSqlSessionFactoryBeanName(String)} instead.
*
- * @param sqlSessionFactory
+ * @param sqlSessionFactory a factory of SqlSession
*/
@Deprecated
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
@@ -231,10 +230,12 @@ public void setSqlSessionFactoryBeanName(String sqlSessionFactoryName) {
}
/**
- *
+ * Specifies a flag that whether execute a property placeholder processing or not.
+ *
+ * The default is {@literal false}. This means that a property placeholder processing does not execute.
* @since 1.1.1
*
- * @param processPropertyPlaceHolders
+ * @param processPropertyPlaceHolders a flag that whether execute a property placeholder processing or not
*/
public void setProcessPropertyPlaceHolders(boolean processPropertyPlaceHolders) {
this.processPropertyPlaceHolders = processPropertyPlaceHolders;
diff --git a/src/main/java/org/mybatis/spring/support/SqlSessionDaoSupport.java b/src/main/java/org/mybatis/spring/support/SqlSessionDaoSupport.java
index 4aee710848..a969b5e271 100644
--- a/src/main/java/org/mybatis/spring/support/SqlSessionDaoSupport.java
+++ b/src/main/java/org/mybatis/spring/support/SqlSessionDaoSupport.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,8 @@ public abstract class SqlSessionDaoSupport extends DaoSupport {
/**
* Set MyBatis SqlSessionFactory to be used by this DAO.
* Will automatically create SqlSessionTemplate for the given SqlSessionFactory.
+ *
+ * @param sqlSessionFactory a factory of SqlSession
*/
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
if (this.sqlSessionTemplate == null || sqlSessionFactory != this.sqlSessionTemplate.getSqlSessionFactory()) {
@@ -67,6 +69,8 @@ protected SqlSessionTemplate createSqlSessionTemplate(SqlSessionFactory sqlSessi
/**
* Return the MyBatis SqlSessionFactory used by this DAO.
+ *
+ * @return a factory of SqlSession
*/
public final SqlSessionFactory getSqlSessionFactory() {
return (this.sqlSessionTemplate != null ? this.sqlSessionTemplate.getSqlSessionFactory() : null);
@@ -76,6 +80,8 @@ public final SqlSessionFactory getSqlSessionFactory() {
/**
* Set the SqlSessionTemplate for this DAO explicitly,
* as an alternative to specifying a SqlSessionFactory.
+ *
+ * @param sqlSessionTemplate a template of SqlSession
* @see #setSqlSessionFactory
*/
public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
@@ -102,6 +108,8 @@ public SqlSession getSqlSession() {
* Consider creating a custom SqlSessionTemplate instance via
* {@code new SqlSessionTemplate(getSqlSessionFactory())}, in which case
* you're allowed to customize the settings on the resulting instance.
+ *
+ * @return a template of SqlSession
*/
public SqlSessionTemplate getSqlSessionTemplate() {
return this.sqlSessionTemplate;
From 450362169d36dacfc33cd8e10d87a39f5d079931 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Fri, 4 May 2018 15:45:36 +0900
Subject: [PATCH 028/933] Add explanation for
MyBatisBatchItemWriter#itemToParameterConverter on doc See #21
---
src/site/es/xdoc/batch.xml | 67 +++++++++++++++++-
src/site/ja/xdoc/batch.xml | 70 ++++++++++++++++++-
src/site/ko/xdoc/batch.xml | 68 +++++++++++++++++-
src/site/xdoc/batch.xml | 66 ++++++++++++++++-
src/site/zh/xdoc/batch.xml | 66 +++++++++++++++++
.../spring/sample/AbstractSampleJobTest.java | 16 ++++-
.../sample/SampleJobJavaConfigTest.java | 6 +-
.../spring/sample/SampleJobXmlConfigTest.java | 7 +-
.../spring/sample/config/SampleJobConfig.java | 17 ++++-
.../sample/config/applicationContext-job.xml | 8 ++-
.../spring/sample/db/database-schema.sql | 6 +-
.../spring/sample/mapper/PersonMapper.xml | 9 +--
12 files changed, 391 insertions(+), 15 deletions(-)
diff --git a/src/site/es/xdoc/batch.xml b/src/site/es/xdoc/batch.xml
index f5de8c226b..7963bf740c 100644
--- a/src/site/es/xdoc/batch.xml
+++ b/src/site/es/xdoc/batch.xml
@@ -1,7 +1,7 @@
+
+
+
+
+
+
+
+
+
+
+]]>
+
Escribiendo en distintas tablas usando composite writers (con algunos condicionantes):
Esta técnica sólo puede usarse con MyBatis 3.2+, por que había un
diff --git a/src/site/ja/xdoc/batch.xml b/src/site/ja/xdoc/batch.xml
index 28ee1b0461..b68b309d3c 100644
--- a/src/site/ja/xdoc/batch.xml
+++ b/src/site/ja/xdoc/batch.xml
@@ -1,7 +1,7 @@
+
+
+
+
+
+
+
+
+
+
+]]>
+
+
여러개의 테이블에 데이터를 쓰려면 한꺼번에 처리할 수 있도록 만든 writer(몇가지 규칙을 가지고)를 사용하자.
이 기능은 마이바티스 3.2이상에서만 사용할 수 있다. 이전의 버전에서는 예상과 다르게 동작하는데 그 내용은
diff --git a/src/site/xdoc/batch.xml b/src/site/xdoc/batch.xml
index 507f4c9ae1..8083827f91 100644
--- a/src/site/xdoc/batch.xml
+++ b/src/site/xdoc/batch.xml
@@ -1,7 +1,7 @@
+
+
+
+
+
+
+
+
+
+
+]]>
+
Writing to different tables using composite writers (with some caveats):
This technique can only be used with MyBatis 3.2+, as there was an
diff --git a/src/site/zh/xdoc/batch.xml b/src/site/zh/xdoc/batch.xml
index e9c90aa4c6..0e519959a3 100644
--- a/src/site/zh/xdoc/batch.xml
+++ b/src/site/zh/xdoc/batch.xml
@@ -200,6 +200,72 @@ public MyBatisBatchItemWriter writer() {
.build();
}]]>
+
+
Converting a item that read using ItemReader to an any parameter object:
+
+
+ By default behavior, the MyBatisBatchItemWriter passes a item that read using ItemReader
+ (or convert by ItemProcessor) to the MyBatis(SqlSession#update()) as the parameter object.
+ If you want to customize a parameter object that passes to the MyBatis, you can realize to use the itemToParameterConverter option.
+ For example using itemToParameterConverter option, you can passes any objects other than the item object to the MyBatis.
+ Follows below a sample:
+
+
+
+ At first, you create a custom converter class (or factory method). The following sample uses a factory method.
+
diff --git a/src/test/java/org/mybatis/spring/sample/AbstractSampleJobTest.java b/src/test/java/org/mybatis/spring/sample/AbstractSampleJobTest.java
index 7740a0fc2d..918593066f 100644
--- a/src/test/java/org/mybatis/spring/sample/AbstractSampleJobTest.java
+++ b/src/test/java/org/mybatis/spring/sample/AbstractSampleJobTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2017 the original author or authors.
+ * Copyright 2010-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,38 +47,52 @@ void testJob() throws Exception {
List
-
\ No newline at end of file
+
diff --git a/src/site/ja/xdoc/mappers.xml b/src/site/ja/xdoc/mappers.xml
index 1f8fc2508c..ff7f13a4dd 100644
--- a/src/site/ja/xdoc/mappers.xml
+++ b/src/site/ja/xdoc/mappers.xml
@@ -110,7 +110,24 @@ public MapperFactoryBean userMapper() throws Exception {
Spring の XML 設定ファイルに MapperScannerConfigurer のエントリーを追加する。
<mybatis:scan/> 와 @MapperScan 모두 마이바티스 스프링 연동모듈 1.2.0에서 추가된 기능이다.
- @MapperScan 은 스프링 버전이 3.1이상이어야 한다.
+ @MapperScan 은 스프링 버전이 3.1이상이어야 한다.
+
+
+ Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
+ that control lazy initialization enabled/disabled of mapper bean.
+ The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
+ The default of this option is false (= not use lazy initialization).
+ If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
+
+
+ IMPORTANT If use the lazy initialization feature,
+ the developer need to understand following limitations. If any of following conditions are matches,
+ the lazy initialization feature cannot use on your application.
+
+
+
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
+
When includes to the fragment of other mapper using ]]>
+
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
+
When refers to the result mapping of other mapper using ]]>(@ResultMap)
Both <mybatis:scan/> and @MapperScan are features introduced in MyBatis-Spring 1.2.0.
- @MapperScan requires Spring 3.1+.
+ @MapperScan requires Spring 3.1+.
+
+
+ Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
+ that control lazy initialization enabled/disabled of mapper bean.
+ The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
+ The default of this option is false (= not use lazy initialization).
+ If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
+
+
+ IMPORTANT If use the lazy initialization feature,
+ the developer need to understand following limitations. If any of following conditions are matches,
+ the lazy initialization feature cannot use on your application.
+
+
+
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
+
When includes to the fragment of other mapper using ]]>
+
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
+
When refers to the result mapping of other mapper using ]]>(@ResultMap)
<mybatis:scan/> 和 @MapperScan 都在 MyBatis-Spring 1.2.0 中被引入。@MapperScan 需要你使用 Spring 3.1+。
+
+ Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
+ that control lazy initialization enabled/disabled of mapper bean.
+ The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
+ The default of this option is false (= not use lazy initialization).
+ If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
+
+
+ IMPORTANT If use the lazy initialization feature,
+ the developer need to understand following limitations. If any of following conditions are matches,
+ the lazy initialization feature cannot use on your application.
+
+
+
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
+
When includes to the fragment of other mapper using ]]>
+
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
+
When refers to the result mapping of other mapper using ]]>(@ResultMap)
IMPORTANT If use the lazy initialization feature,
the developer need to understand following limitations. If any of following conditions are matches,
- the lazy initialization feature cannot use on your application.
+ usually the lazy initialization feature cannot use on your application.
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
@@ -142,6 +142,15 @@ public MapperFactoryBean userMapper() throws Exception {
When refers to the result mapping of other mapper using ]]>(@ResultMap)
+
+ NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
+
IMPORTANT If use the lazy initialization feature,
the developer need to understand following limitations. If any of following conditions are matches,
- the lazy initialization feature cannot use on your application.
+ usually the lazy initialization feature cannot use on your application.
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
@@ -118,6 +118,15 @@ public MapperFactoryBean userMapper() throws Exception {
When refers to the result mapping of other mapper using ]]>(@ResultMap)
+
+ NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
+
+
+
+
<mybatis:scan/>
<mybatis:scan/> XML엘리먼트는 스프링에서 제공하는 <context:component-scan/> 엘리먼트와 매우 유사한 방법으로 매퍼를 검색할 것이다.
IMPORTANT If use the lazy initialization feature,
the developer need to understand following limitations. If any of following conditions are matches,
- the lazy initialization feature cannot use on your application.
+ usually the lazy initialization feature cannot use on your application.
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
@@ -145,6 +145,15 @@ public MapperFactoryBean userMapper() throws Exception {
When refers to the result mapping of other mapper using ]]>(@ResultMap)
+
+ NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
+
IMPORTANT If use the lazy initialization feature,
the developer need to understand following limitations. If any of following conditions are matches,
- the lazy initialization feature cannot use on your application.
+ usually the lazy initialization feature cannot use on your application.
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
@@ -126,6 +126,15 @@ public MapperFactoryBean userMapper() throws Exception {
When refers to the result mapping of other mapper using ]]>(@ResultMap)
+
+ NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
+
+
+
+
<mybatis:scan/>
From b4042aded41cab7d9ec16e1225365a3db462c956 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Wed, 1 May 2019 17:57:58 +0900
Subject: [PATCH 123/933] Add license header
---
.editorconfig | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/.editorconfig b/.editorconfig
index a7dcff48e0..7cd8a144e3 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,3 +1,19 @@
+#
+# Copyright 2010-2019 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
root = true
[*.{java, xml, sql}]
From 54f6166ef3f50f04b910141fcd9a00333a1b95fe Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Thu, 2 May 2019 17:26:37 +0900
Subject: [PATCH 124/933] Support to configure LanguageDriver via
SqlSessionFactoryBean Fixes gh-378
---
.../mybatis/spring/SqlSessionFactoryBean.java | 36 +++++++++++++++
.../spring/SqlSessionFactoryBeanTest.java | 46 +++++++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
index c42679fae9..1674a2de99 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
@@ -36,6 +36,7 @@
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
+import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
@@ -125,6 +126,10 @@ public class SqlSessionFactoryBean
private Class> typeAliasesSuperType;
+ private LanguageDriver[] scriptingLanguageDrivers;
+
+ private Class extends LanguageDriver> defaultScriptingLanguageDriver;
+
// issue #19. No default provider.
private DatabaseIdProvider databaseIdProvider;
@@ -435,6 +440,28 @@ public void setEnvironment(String environment) {
this.environment = environment;
}
+ /**
+ * Set scripting language drivers.
+ *
+ * @param scriptingLanguageDrivers
+ * scripting language drivers
+ * @since 2.0.2
+ */
+ public void setScriptingLanguageDrivers(LanguageDriver... scriptingLanguageDrivers) {
+ this.scriptingLanguageDrivers = scriptingLanguageDrivers;
+ }
+
+ /**
+ * Set a default scripting language driver class.
+ *
+ * @param defaultScriptingLanguageDriver
+ * A default scripting language driver class
+ * @since 2.0.2
+ */
+ public void setDefaultScriptingLanguageDriver(Class extends LanguageDriver> defaultScriptingLanguageDriver) {
+ this.defaultScriptingLanguageDriver = defaultScriptingLanguageDriver;
+ }
+
/**
* {@inheritDoc}
*/
@@ -519,6 +546,15 @@ protected SqlSessionFactory buildSqlSessionFactory() throws Exception {
});
}
+ if (!isEmpty(this.scriptingLanguageDrivers)) {
+ Stream.of(this.scriptingLanguageDrivers).forEach(languageDriver -> {
+ targetConfiguration.getLanguageRegistry().register(languageDriver);
+ LOGGER.debug(() -> "Registered scripting language driver: '" + languageDriver + "'");
+ });
+ }
+ Optional.ofNullable(this.defaultScriptingLanguageDriver)
+ .ifPresent(targetConfiguration::setDefaultScriptingLanguage);
+
if (this.databaseIdProvider != null) {// fix #64 set databaseId before parse mapper xmls
try {
targetConfiguration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
diff --git a/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java b/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
index abcb81d70e..27a156e346 100644
--- a/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
+++ b/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
@@ -29,6 +29,10 @@
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
+import org.apache.ibatis.scripting.LanguageDriver;
+import org.apache.ibatis.scripting.LanguageDriverRegistry;
+import org.apache.ibatis.scripting.defaults.RawLanguageDriver;
+import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSessionFactory;
@@ -440,6 +444,42 @@ void testAddCache() {
assertThat(this.factoryBean.getCache().getId()).isEqualTo("test-cache");
}
+ @Test
+ void testScriptingLanguageDriverEmpty() throws Exception {
+ setupFactoryBean();
+ this.factoryBean.setScriptingLanguageDrivers();
+ LanguageDriverRegistry registry = this.factoryBean.getObject().getConfiguration().getLanguageRegistry();
+ assertThat(registry.getDefaultDriver()).isInstanceOf(XMLLanguageDriver.class);
+ assertThat(registry.getDefaultDriverClass()).isEqualTo(XMLLanguageDriver.class);
+ }
+
+ @Test
+ void testScriptingLanguageDriver() throws Exception {
+ setupFactoryBean();
+ this.factoryBean.setScriptingLanguageDrivers(new MyLanguageDriver1(), new MyLanguageDriver2());
+ LanguageDriverRegistry registry = this.factoryBean.getObject().getConfiguration().getLanguageRegistry();
+ assertThat(registry.getDefaultDriver()).isInstanceOf(XMLLanguageDriver.class);
+ assertThat(registry.getDefaultDriverClass()).isEqualTo(XMLLanguageDriver.class);
+ assertThat(registry.getDriver(MyLanguageDriver1.class)).isNotNull();
+ assertThat(registry.getDriver(MyLanguageDriver2.class)).isNotNull();
+ assertThat(registry.getDriver(XMLLanguageDriver.class)).isNotNull();
+ assertThat(registry.getDriver(RawLanguageDriver.class)).isNotNull();
+ }
+
+ @Test
+ void testScriptingLanguageDriverWithDefault() throws Exception {
+ setupFactoryBean();
+ this.factoryBean.setScriptingLanguageDrivers(new MyLanguageDriver1(), new MyLanguageDriver2());
+ this.factoryBean.setDefaultScriptingLanguageDriver(MyLanguageDriver1.class);
+ LanguageDriverRegistry registry = this.factoryBean.getObject().getConfiguration().getLanguageRegistry();
+ assertThat(registry.getDefaultDriver()).isInstanceOf(MyLanguageDriver1.class);
+ assertThat(registry.getDefaultDriverClass()).isEqualTo(MyLanguageDriver1.class);
+ assertThat(registry.getDriver(MyLanguageDriver1.class)).isNotNull();
+ assertThat(registry.getDriver(MyLanguageDriver2.class)).isNotNull();
+ assertThat(registry.getDriver(XMLLanguageDriver.class)).isNotNull();
+ assertThat(registry.getDriver(RawLanguageDriver.class)).isNotNull();
+ }
+
private void assertDefaultConfig(SqlSessionFactory factory) {
assertConfig(factory, SqlSessionFactoryBean.class.getSimpleName(),
org.mybatis.spring.transaction.SpringManagedTransactionFactory.class);
@@ -464,4 +504,10 @@ private void assertConfig(SqlSessionFactory factory, String environment,
assertThat(factory.getConfiguration().getSqlFragments().size()).isEqualTo(0);
}
+ private static class MyLanguageDriver1 extends RawLanguageDriver {
+ }
+
+ private static class MyLanguageDriver2 extends RawLanguageDriver {
+ }
+
}
From 1fafc59997fa806168578ffc7c0b117403724520 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Fri, 3 May 2019 00:37:18 +0900
Subject: [PATCH 125/933] Change to Variable-length argument from array
argument on SqlSessionFactoryBean
---
.../java/org/mybatis/spring/SqlSessionFactoryBean.java | 8 ++++----
.../org/mybatis/spring/AbstractMyBatisSpringTest.java | 4 ++--
.../org/mybatis/spring/SqlSessionFactoryBeanTest.java | 8 ++++----
.../org/mybatis/spring/mapper/MapperFactoryBeanTest.java | 2 +-
.../org/mybatis/spring/sample/config/SampleConfig.java | 2 +-
5 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
index 1674a2de99..0689f317cb 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
@@ -231,7 +231,7 @@ public void setCache(Cache cache) {
* list of plugins
*
*/
- public void setPlugins(Interceptor[] plugins) {
+ public void setPlugins(Interceptor... plugins) {
this.plugins = plugins;
}
@@ -289,7 +289,7 @@ public void setTypeHandlersPackage(String typeHandlersPackage) {
* @param typeHandlers
* Type handler list
*/
- public void setTypeHandlers(TypeHandler>[] typeHandlers) {
+ public void setTypeHandlers(TypeHandler>... typeHandlers) {
this.typeHandlers = typeHandlers;
}
@@ -301,7 +301,7 @@ public void setTypeHandlers(TypeHandler>[] typeHandlers) {
* @param typeAliases
* Type aliases list
*/
- public void setTypeAliases(Class>[] typeAliases) {
+ public void setTypeAliases(Class>... typeAliases) {
this.typeAliases = typeAliases;
}
@@ -351,7 +351,7 @@ public void setConfiguration(Configuration configuration) {
* @param mapperLocations
* location of MyBatis mapper files
*/
- public void setMapperLocations(Resource[] mapperLocations) {
+ public void setMapperLocations(Resource... mapperLocations) {
this.mapperLocations = mapperLocations;
}
diff --git a/src/test/java/org/mybatis/spring/AbstractMyBatisSpringTest.java b/src/test/java/org/mybatis/spring/AbstractMyBatisSpringTest.java
index 784686f6fe..7c01b9d1c3 100644
--- a/src/test/java/org/mybatis/spring/AbstractMyBatisSpringTest.java
+++ b/src/test/java/org/mybatis/spring/AbstractMyBatisSpringTest.java
@@ -53,10 +53,10 @@ public abstract class AbstractMyBatisSpringTest {
public static void setupBase() throws Exception {
// create an SqlSessionFactory that will use SpringManagedTransactions
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
- factoryBean.setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/TestMapper.xml") });
+ factoryBean.setMapperLocations(new ClassPathResource("org/mybatis/spring/TestMapper.xml"));
// note running without SqlSessionFactoryBean.configLocation set => default configuration
factoryBean.setDataSource(dataSource);
- factoryBean.setPlugins(new Interceptor[] { executorInterceptor });
+ factoryBean.setPlugins(executorInterceptor);
exceptionTranslator = new MyBatisExceptionTranslator(dataSource, true);
diff --git a/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java b/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
index 27a156e346..396c8011d1 100644
--- a/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
+++ b/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
@@ -301,7 +301,7 @@ void testSpecifyConfigurationAndConfigLocation() throws Exception {
void testFragmentsAreReadWithMapperLocations() throws Exception {
setupFactoryBean();
- factoryBean.setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/TestMapper.xml") });
+ factoryBean.setMapperLocations(new ClassPathResource("org/mybatis/spring/TestMapper.xml"));
SqlSessionFactory factory = factoryBean.getObject();
@@ -321,7 +321,7 @@ void testNullMapperLocations() throws Exception {
@Test
void testEmptyMapperLocations() throws Exception {
setupFactoryBean();
- factoryBean.setMapperLocations(new org.springframework.core.io.Resource[0]);
+ factoryBean.setMapperLocations();
assertDefaultConfig(factoryBean.getObject());
}
@@ -337,7 +337,7 @@ void testMapperLocationsWithNullEntry() throws Exception {
@Test
void testAddATypeHandler() throws Exception {
setupFactoryBean();
- factoryBean.setTypeHandlers(new TypeHandler[] { new DummyTypeHandler() });
+ factoryBean.setTypeHandlers(new DummyTypeHandler());
TypeHandlerRegistry typeHandlerRegistry = factoryBean.getObject().getConfiguration().getTypeHandlerRegistry();
assertThat(typeHandlerRegistry.hasTypeHandler(BigInteger.class)).isTrue();
@@ -347,7 +347,7 @@ void testAddATypeHandler() throws Exception {
void testAddATypeAlias() throws Exception {
setupFactoryBean();
- factoryBean.setTypeAliases(new Class[] { DummyTypeAlias.class });
+ factoryBean.setTypeAliases(DummyTypeAlias.class);
TypeAliasRegistry typeAliasRegistry = factoryBean.getObject().getConfiguration().getTypeAliasRegistry();
typeAliasRegistry.resolveAlias("testAlias");
}
diff --git a/src/test/java/org/mybatis/spring/mapper/MapperFactoryBeanTest.java b/src/test/java/org/mybatis/spring/mapper/MapperFactoryBeanTest.java
index 953c7ef4dd..bf08452d2c 100644
--- a/src/test/java/org/mybatis/spring/mapper/MapperFactoryBeanTest.java
+++ b/src/test/java/org/mybatis/spring/mapper/MapperFactoryBeanTest.java
@@ -64,7 +64,7 @@ void testAddToConfigTrue() throws Exception {
factoryBean.setDatabaseIdProvider(null);
// mapperLocations properties defaults to null
factoryBean.setDataSource(dataSource);
- factoryBean.setPlugins(new Interceptor[] { executorInterceptor });
+ factoryBean.setPlugins(executorInterceptor);
SqlSessionFactory sqlSessionFactory = factoryBean.getObject();
diff --git a/src/test/java/org/mybatis/spring/sample/config/SampleConfig.java b/src/test/java/org/mybatis/spring/sample/config/SampleConfig.java
index 7682170aa7..b09bbe07c0 100644
--- a/src/test/java/org/mybatis/spring/sample/config/SampleConfig.java
+++ b/src/test/java/org/mybatis/spring/sample/config/SampleConfig.java
@@ -50,7 +50,7 @@ public PlatformTransactionManager transactionalManager() {
public SqlSessionFactory sqlSessionFactory() throws Exception {
SqlSessionFactoryBean ss = new SqlSessionFactoryBean();
ss.setDataSource(dataSource());
- ss.setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/sample/mapper/UserMapper.xml") });
+ ss.setMapperLocations(new ClassPathResource("org/mybatis/spring/sample/mapper/UserMapper.xml"));
return ss.getObject();
}
From 1e1bf2a73b375118015e9926f99160d66332c21d Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 6 May 2019 00:27:56 +0900
Subject: [PATCH 126/933] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index a278b46aa1..95f4235b90 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@ MyBatis Spring Adapter
[](https://travis-ci.org/mybatis/spring)
[](https://coveralls.io/github/mybatis/spring?branch=master)
[](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis-spring)
+[](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis-spring)
[](http://www.apache.org/licenses/LICENSE-2.0.html)

From 9cfac7459bd132bf374fec1a535a39c755cd6fa9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=9D=B3=E9=98=B3?= <260893248@qq.com>
Date: Mon, 17 Jun 2019 09:34:30 +0800
Subject: [PATCH 127/933] an -> a
an -> a
---
src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
index 0689f317cb..3db0b2ce56 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
@@ -68,7 +68,7 @@
import static org.springframework.util.StringUtils.tokenizeToStringArray;
/**
- * {@code FactoryBean} that creates an MyBatis {@code SqlSessionFactory}. This is the usual way to set up a shared
+ * {@code FactoryBean} that creates a MyBatis {@code SqlSessionFactory}. This is the usual way to set up a shared
* MyBatis {@code SqlSessionFactory} in a Spring application context; the SqlSessionFactory can then be passed to
* MyBatis-based DAOs via dependency injection.
*
From ae65b320c6081ae56b5a0bdad321bbbfbd2cec56 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 29 Jun 2019 14:21:01 +0900
Subject: [PATCH 128/933] Replace to openjdk11 on Travis CI Fixes gh-384
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 48cf2b99fa..cc2019d621 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
language: java
jdk:
- - oraclejdk11
+ - openjdk11
- oraclejdk8
after_success:
From 046f250651327a095c7e8d5254568d5cc6bdedd7 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Tue, 2 Jul 2019 00:27:06 +0900
Subject: [PATCH 129/933] Support openjdk12 on Travis CI Fixes gh-385
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index cc2019d621..a427b76232 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,7 @@
language: java
jdk:
+ - openjdk12
- openjdk11
- oraclejdk8
From 33b79ca6609bf76d70d998a39fc5ef7e5678c35a Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Wed, 3 Jul 2019 13:33:52 +0900
Subject: [PATCH 130/933] Upgrade to spring 5.1.8 Fixes gh-387
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5502714cef..3a20787d4e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.1
- 5.1.6.RELEASE
+ 5.1.8.RELEASE4.1.2.RELEASEorg.mybatis.spring
From e07508ef47bba8699d16db3eb17f59b5129650e7 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 6 Jul 2019 23:13:20 +0900
Subject: [PATCH 131/933] Upgrade to JUnit 5.5
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3a20787d4e..16b01ed7e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,7 +110,7 @@
4.1.2.RELEASEorg.mybatis.spring
- 5.4.2
+ 5.5.0
From c428e8cac3c61683bf327792148b906895d95297 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 15 Jul 2019 11:36:48 +0900
Subject: [PATCH 132/933] Upgrade to mybatis 3.5.2 Fixes gh-388
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 16b01ed7e8..65130a356a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,7 +105,7 @@
org.springframework.batch.*;resolution:=optional,**
- 3.5.1
+ 3.5.25.1.8.RELEASE4.1.2.RELEASEorg.mybatis.spring
From 89cc8b8697278c2bb493b81c728e3975990df2f6 Mon Sep 17 00:00:00 2001
From: Iwao AVE!
Date: Mon, 15 Jul 2019 12:10:54 +0900
Subject: [PATCH 133/933] [maven-release-plugin] prepare release
mybatis-spring-2.0.2
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 65130a356a..c816a08c8d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
mybatis-spring
- 2.0.2-SNAPSHOT
+ 2.0.2jarmybatis-spring
@@ -80,7 +80,7 @@
http://github.com/mybatis/springscm:git:ssh://github.com/mybatis/spring.gitscm:git:ssh://git@github.com/mybatis/spring.git
- HEAD
+ mybatis-spring-2.0.2GitHub Issue Management
From f7db7f36059a9761a9453aad20402b2d0a55ce54 Mon Sep 17 00:00:00 2001
From: Iwao AVE!
Date: Mon, 15 Jul 2019 12:11:01 +0900
Subject: [PATCH 134/933] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index c816a08c8d..1c11db0e5c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
mybatis-spring
- 2.0.2
+ 2.0.3-SNAPSHOTjarmybatis-spring
@@ -80,7 +80,7 @@
http://github.com/mybatis/springscm:git:ssh://github.com/mybatis/spring.gitscm:git:ssh://git@github.com/mybatis/spring.git
- mybatis-spring-2.0.2
+ HEADGitHub Issue Management
From 6fd6f1081fe3d2d9e96246a91c829ad24c9aadea Mon Sep 17 00:00:00 2001
From: Jeremy Landis
Date: Mon, 15 Jul 2019 19:10:00 -0400
Subject: [PATCH 135/933] [mvn] Update maven wrapper to 0.5.5
---
.mvn/wrapper/MavenWrapperDownloader.java | 4 ++--
.mvn/wrapper/maven-wrapper.properties | 3 +--
mvnw | 9 +++++--
mvnw.cmd | 30 ++++++++++++++++--------
4 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java
index b20a55a7a9..c32394f140 100644
--- a/.mvn/wrapper/MavenWrapperDownloader.java
+++ b/.mvn/wrapper/MavenWrapperDownloader.java
@@ -20,12 +20,12 @@
public class MavenWrapperDownloader {
- private static final String WRAPPER_VERSION = "0.5.3";
+ private static final String WRAPPER_VERSION = "0.5.5";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
- + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + " .jar";
+ + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index 33ccdc4c9a..fa87ad7ddf 100644
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -1,3 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
-wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar
-
+wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
diff --git a/mvnw b/mvnw
index 34d9dae8d0..d2f0ea3808 100755
--- a/mvnw
+++ b/mvnw
@@ -212,9 +212,9 @@ else
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
- jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+ jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
else
- jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+ jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
fi
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
@@ -296,6 +296,11 @@ if $cygwin; then
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
diff --git a/mvnw.cmd b/mvnw.cmd
index 77b451d837..b26ab24f03 100644
--- a/mvnw.cmd
+++ b/mvnw.cmd
@@ -37,7 +37,7 @@
@echo off
@REM set title of command window
title %0
-@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
@@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
@@ -129,14 +129,18 @@ FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
- echo Found %WRAPPER_JAR%
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Found %WRAPPER_JAR%
+ )
) else (
- if not "%MVNW_REPOURL%" == "" (
- SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar"
- )
- echo Couldn't find %WRAPPER_JAR%, downloading it ...
- echo Downloading from: %DOWNLOAD_URL%
-
+ if not "%MVNW_REPOURL%" == "" (
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
+ )
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %DOWNLOAD_URL%
+ )
+
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
@@ -144,10 +148,16 @@ if exist %WRAPPER_JAR% (
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
- echo Finished downloading %WRAPPER_JAR%
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Finished downloading %WRAPPER_JAR%
+ )
)
@REM End of extension
+@REM Provide a "standardized" way to retrieve the CLI args that will
+@REM work with both Windows and non-Windows executions.
+set MAVEN_CMD_LINE_ARGS=%*
+
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
From 03c62f3e991bcbaa25a199308fc311499737c12d Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Fri, 19 Jul 2019 02:53:29 +0900
Subject: [PATCH 136/933] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 95f4235b90..c9998ae095 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ MyBatis Spring Adapter
[](https://travis-ci.org/mybatis/spring)
[](https://coveralls.io/github/mybatis/spring?branch=master)
[](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis-spring)
-[](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis-spring)
+[](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis-spring/)
[](http://www.apache.org/licenses/LICENSE-2.0.html)

From dd5a9ffba2e35f43e1f53f888b9ebfafe600877a Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sun, 21 Jul 2019 04:58:08 +0900
Subject: [PATCH 137/933] Allow to scan TypeHandler that pass Class> to
constructor Fixes gh-394
---
.../mybatis/spring/SqlSessionFactoryBean.java | 13 +++--
.../jdk/type/AtomicNumberTypeHandler.java | 54 +++++++++++++++++++
.../spring/SqlSessionFactoryBeanTest.java | 7 ++-
3 files changed, 66 insertions(+), 8 deletions(-)
create mode 100644 src/test/java/org/mybatis/core/jdk/type/AtomicNumberTypeHandler.java
diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
index 3db0b2ce56..fb7463e168 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
@@ -186,7 +186,7 @@ public void setDatabaseIdProvider(DatabaseIdProvider databaseIdProvider) {
/**
* Gets the VFS.
- *
+ *
* @return a specified VFS
*/
public Class extends VFS> getVfs() {
@@ -195,7 +195,7 @@ public Class extends VFS> getVfs() {
/**
* Sets the VFS.
- *
+ *
* @param vfs
* a VFS
*/
@@ -205,7 +205,7 @@ public void setVfs(Class extends VFS> vfs) {
/**
* Gets the Cache.
- *
+ *
* @return a specified Cache
*/
public Cache getCache() {
@@ -214,7 +214,7 @@ public Cache getCache() {
/**
* Sets the Cache.
- *
+ *
* @param cache
* a Cache
*/
@@ -270,7 +270,7 @@ public void setTypeAliasesSuperType(Class> typeAliasesSuperType) {
*
*
* Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.typehandler}.
- *
+ *
* @since 1.0.1
*
* @param typeHandlersPackage
@@ -331,7 +331,7 @@ public void setConfigLocation(Resource configLocation) {
/**
* Set a customized MyBatis configuration.
- *
+ *
* @param configuration
* MyBatis configuration
* @since 1.3.0
@@ -535,7 +535,6 @@ protected SqlSessionFactory buildSqlSessionFactory() throws Exception {
if (hasLength(this.typeHandlersPackage)) {
scanClasses(this.typeHandlersPackage, TypeHandler.class).stream().filter(clazz -> !clazz.isAnonymousClass())
.filter(clazz -> !clazz.isInterface()).filter(clazz -> !Modifier.isAbstract(clazz.getModifiers()))
- .filter(clazz -> ClassUtils.getConstructorIfAvailable(clazz) != null)
.forEach(targetConfiguration.getTypeHandlerRegistry()::register);
}
diff --git a/src/test/java/org/mybatis/core/jdk/type/AtomicNumberTypeHandler.java b/src/test/java/org/mybatis/core/jdk/type/AtomicNumberTypeHandler.java
new file mode 100644
index 0000000000..b1935e3c01
--- /dev/null
+++ b/src/test/java/org/mybatis/core/jdk/type/AtomicNumberTypeHandler.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2010-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.mybatis.core.jdk.type;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.ibatis.type.JdbcType;
+import org.apache.ibatis.type.MappedTypes;
+import org.apache.ibatis.type.TypeHandler;
+
+@MappedTypes({ AtomicInteger.class, AtomicLong.class })
+public class AtomicNumberTypeHandler implements TypeHandler {
+
+ public AtomicNumberTypeHandler(Class> type) {
+ }
+
+ @Override
+ public void setParameter(PreparedStatement ps, int i, Number parameter, JdbcType jdbcType) throws SQLException {
+ }
+
+ @Override
+ public Number getResult(ResultSet rs, String columnName) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Number getResult(CallableStatement cs, int columnIndex) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Number getResult(ResultSet rs, int columnIndex) throws SQLException {
+ return null;
+ }
+
+}
diff --git a/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java b/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
index 396c8011d1..d373ff51db 100644
--- a/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
+++ b/src/test/java/org/mybatis/spring/SqlSessionFactoryBeanTest.java
@@ -22,6 +22,8 @@
import java.math.BigInteger;
import java.util.Properties;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.ibatis.cache.impl.PerpetualCache;
import org.apache.ibatis.io.JBoss6VFS;
@@ -43,6 +45,7 @@
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.junit.jupiter.api.Test;
+import org.mybatis.core.jdk.type.AtomicNumberTypeHandler;
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
import org.mybatis.spring.type.DummyTypeAlias;
import org.mybatis.spring.type.DummyTypeHandler;
@@ -400,12 +403,14 @@ void testSearchATypeAliasPackageWithSamePackage() throws Exception {
@Test
void testSearchATypeHandlerPackage() throws Exception {
setupFactoryBean();
- factoryBean.setTypeHandlersPackage("org.**.type");
+ factoryBean.setTypeHandlersPackage("org.mybatis.**.type");
TypeHandlerRegistry typeHandlerRegistry = factoryBean.getObject().getConfiguration().getTypeHandlerRegistry();
assertThat(typeHandlerRegistry.hasTypeHandler(BigInteger.class)).isTrue();
assertThat(typeHandlerRegistry.hasTypeHandler(BigDecimal.class)).isTrue();
assertThat(typeHandlerRegistry.getTypeHandler(UUID.class)).isInstanceOf(TypeHandlerFactory.InnerTypeHandler.class);
+ assertThat(typeHandlerRegistry.getTypeHandler(AtomicInteger.class)).isInstanceOf(AtomicNumberTypeHandler.class);
+ assertThat(typeHandlerRegistry.getTypeHandler(AtomicLong.class)).isInstanceOf(AtomicNumberTypeHandler.class);
}
@Test
From 2e7b4f8466c773b63bfb06379b9caafa0575a0bd Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 10 Aug 2019 02:32:45 +0900
Subject: [PATCH 138/933] Change sonar.host.url
---
travis/after_success.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/travis/after_success.sh b/travis/after_success.sh
index ee45ba6b5b..d09d4f2f0e 100644
--- a/travis/after_success.sh
+++ b/travis/after_success.sh
@@ -50,7 +50,7 @@ if [ $TRAVIS_REPO_SLUG == "mybatis/spring" ] && [ "$TRAVIS_PULL_REQUEST" == "fal
# echo -e "Successfully deploy site under Travis job ${TRAVIS_JOB_NUMBER}"
# Notify Sonar
- ./mvnw clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=ccf0be39fd0ca5ea5aa712247c79da7233cd3caa
+ ./mvnw clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=ccf0be39fd0ca5ea5aa712247c79da7233cd3caa
echo -e "Successfully ran Sonar integration under Travis job ${TRAVIS_JOB_NUMBER}"
else
echo "Java Version does not support additonal activity for travis CI"
From ec803eccd9c74e93efdabebfea7f427861c1a8fd Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 10 Aug 2019 02:41:16 +0900
Subject: [PATCH 139/933] Switch to use openjdk8 instead of oraclejdk8 on
Travis CI
---
.travis.yml | 2 +-
travis/after_success.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index a427b76232..bc5e980816 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,7 @@ language: java
jdk:
- openjdk12
- openjdk11
- - oraclejdk8
+ - openjdk8
after_success:
- chmod -R 777 ./travis/after_success.sh
diff --git a/travis/after_success.sh b/travis/after_success.sh
index d09d4f2f0e..d8e4c7bb89 100644
--- a/travis/after_success.sh
+++ b/travis/after_success.sh
@@ -34,7 +34,7 @@ echo "Current commit detected: ${commit_message}"
if [ $TRAVIS_REPO_SLUG == "mybatis/spring" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ] && [[ "$commit_message" != *"[maven-release-plugin]"* ]]; then
- if [ $TRAVIS_JDK_VERSION == "oraclejdk8" ]; then
+ if [ $TRAVIS_JDK_VERSION == "openjdk8" ]; then
# Deploy to sonatype
./mvnw clean deploy -q --settings ./travis/settings.xml
From b04ba3740b7ca5c2c3bb02be0cc473d919c13f7e Mon Sep 17 00:00:00 2001
From: evans810 <48586010+evans810@users.noreply.github.com>
Date: Mon, 19 Aug 2019 16:31:56 +0800
Subject: [PATCH 140/933] Update comment in MyBatisBatchItemWriter.java
Modify comment in Line 67. As in code line 150, if assertUpdates is true, only results.size()==1 can pass the validation
---
.../java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
index f51f898522..d389d7ff76 100644
--- a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
+++ b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
@@ -64,7 +64,7 @@ public class MyBatisBatchItemWriter implements ItemWriter, InitializingBea
private Converter itemToParameterConverter = new PassThroughConverter<>();
/**
- * Public setter for the flag that determines whether an assertion is made that all items cause at least one row to be
+ * Public setter for the flag that determines whether an assertion is made that all items cause only one row to be
* updated.
*
* @param assertUpdates
From e03dd5f728cecac7f9a3ed7753b06c73be36500c Mon Sep 17 00:00:00 2001
From: evans810 <48586010+evans810@users.noreply.github.com>
Date: Wed, 21 Aug 2019 11:19:03 +0800
Subject: [PATCH 141/933] Update comment in MyBatisBatchItemWriter.java
Modify comment in Line 67. As if assertUpdates is true, only results.size() == 1 and results.get(0).getUpdateCounts()[i] != 0 can pass the validation
---
.../java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
index d389d7ff76..caf784028c 100644
--- a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
+++ b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
@@ -64,7 +64,7 @@ public class MyBatisBatchItemWriter implements ItemWriter, InitializingBea
private Converter itemToParameterConverter = new PassThroughConverter<>();
/**
- * Public setter for the flag that determines whether an assertion is made that all items cause only one row to be
+ * Public setter for the flag that determines whether an assertion is made that number of BatchResult objects returned is one and all items cause at least one row to be
* updated.
*
* @param assertUpdates
From 81efd343a8527c063a93efde08887479f27765b1 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Tue, 10 Sep 2019 01:11:55 +0900
Subject: [PATCH 142/933] Allow to configure the SQLExceptionTranslator on
MyBatisExceptionTranslator Fixes gh-400
---
.../spring/MyBatisExceptionTranslator.java | 24 +++++++++++++++----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/MyBatisExceptionTranslator.java b/src/main/java/org/mybatis/spring/MyBatisExceptionTranslator.java
index f98cf6b126..1f917ff535 100644
--- a/src/main/java/org/mybatis/spring/MyBatisExceptionTranslator.java
+++ b/src/main/java/org/mybatis/spring/MyBatisExceptionTranslator.java
@@ -16,6 +16,7 @@
package org.mybatis.spring;
import java.sql.SQLException;
+import java.util.function.Supplier;
import javax.sql.DataSource;
@@ -37,12 +38,11 @@
*/
public class MyBatisExceptionTranslator implements PersistenceExceptionTranslator {
- private final DataSource dataSource;
-
+ private final Supplier exceptionTranslatorSupplier;
private SQLExceptionTranslator exceptionTranslator;
/**
- * Creates a new {@code DataAccessExceptionTranslator} instance.
+ * Creates a new {@code PersistenceExceptionTranslator} instance with {@code SQLErrorCodeSQLExceptionTranslator}.
*
* @param dataSource
* DataSource to use to find metadata and establish which error codes are usable.
@@ -51,8 +51,22 @@ public class MyBatisExceptionTranslator implements PersistenceExceptionTranslato
* exceptions.
*/
public MyBatisExceptionTranslator(DataSource dataSource, boolean exceptionTranslatorLazyInit) {
- this.dataSource = dataSource;
+ this(() -> new SQLErrorCodeSQLExceptionTranslator(dataSource), exceptionTranslatorLazyInit);
+ }
+ /**
+ * Creates a new {@code PersistenceExceptionTranslator} instance with specified {@code SQLExceptionTranslator}.
+ *
+ * @param exceptionTranslatorSupplier
+ * Supplier for creating a {@code SQLExceptionTranslator} instance
+ * @param exceptionTranslatorLazyInit
+ * if true, the translator instantiates internal stuff only the first time will have the need to translate
+ * exceptions.
+ * @since 2.0.3
+ */
+ public MyBatisExceptionTranslator(Supplier exceptionTranslatorSupplier,
+ boolean exceptionTranslatorLazyInit) {
+ this.exceptionTranslatorSupplier = exceptionTranslatorSupplier;
if (!exceptionTranslatorLazyInit) {
this.initExceptionTranslator();
}
@@ -85,7 +99,7 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
*/
private synchronized void initExceptionTranslator() {
if (this.exceptionTranslator == null) {
- this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(this.dataSource);
+ this.exceptionTranslator = exceptionTranslatorSupplier.get();
}
}
From c86af18115573890f61b9b35dc6590a3bcba7c09 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Tue, 10 Sep 2019 01:53:57 +0900
Subject: [PATCH 143/933] Apply formatter
---
.../java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
index caf784028c..19e16fe7e8 100644
--- a/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
+++ b/src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java
@@ -64,8 +64,8 @@ public class MyBatisBatchItemWriter implements ItemWriter, InitializingBea
private Converter itemToParameterConverter = new PassThroughConverter<>();
/**
- * Public setter for the flag that determines whether an assertion is made that number of BatchResult objects returned is one and all items cause at least one row to be
- * updated.
+ * Public setter for the flag that determines whether an assertion is made that number of BatchResult objects returned
+ * is one and all items cause at least one row to be updated.
*
* @param assertUpdates
* the flag to set. Defaults to true;
From 01386e7e2568c4b110aecbe7fda03de25bb812ab Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 14 Oct 2019 15:02:04 +0900
Subject: [PATCH 144/933] Upgrade to spring 5.1.10 Fixes gh-404
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 1c11db0e5c..70634b436a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.2
- 5.1.8.RELEASE
+ 5.1.10.RELEASE4.1.2.RELEASEorg.mybatis.spring
From 01b244446e49924b490a2d41a44140c72d1c60e3 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 14 Oct 2019 15:08:52 +0900
Subject: [PATCH 145/933] Support spring 5.2 and spring-batch 4.2 on Travis CI
Fixes gh-405
---
.travis.yml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index bc5e980816..982f8be0ac 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,10 @@ jdk:
- openjdk11
- openjdk8
+script:
+ - ./mvnw clean verify
+ - ./mvnw clean verify -Dspring.version=5.2.0.RELEASE -Dspring-batch.version=4.2.0.RELEASE -Denforcer.fail=false
+
after_success:
- chmod -R 777 ./travis/after_success.sh
- ./travis/after_success.sh
From e16c6bb1372d0bcd4e9a0217337ecaeb54e84abd Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sun, 20 Oct 2019 20:34:52 +0900
Subject: [PATCH 146/933] Upgrade to mybatis 3.5.3 Fixes gh-406
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 70634b436a..335f53cc60 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,7 +105,7 @@
org.springframework.batch.*;resolution:=optional,**
- 3.5.2
+ 3.5.35.1.10.RELEASE4.1.2.RELEASEorg.mybatis.spring
From 7572f3e52f49bb15dd0dfdb0696813a1ab2bef52 Mon Sep 17 00:00:00 2001
From: Iwao AVE!
Date: Sun, 20 Oct 2019 20:51:17 +0900
Subject: [PATCH 147/933] [maven-release-plugin] prepare release
mybatis-spring-2.0.3
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 335f53cc60..63ac682afd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
mybatis-spring
- 2.0.3-SNAPSHOT
+ 2.0.3jarmybatis-spring
@@ -80,7 +80,7 @@
http://github.com/mybatis/springscm:git:ssh://github.com/mybatis/spring.gitscm:git:ssh://git@github.com/mybatis/spring.git
- HEAD
+ mybatis-spring-2.0.3GitHub Issue Management
From 12ff817724ade950f7dfda817189f7a2a493e1b9 Mon Sep 17 00:00:00 2001
From: Iwao AVE!
Date: Sun, 20 Oct 2019 20:51:25 +0900
Subject: [PATCH 148/933] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 63ac682afd..2073f9a26b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
mybatis-spring
- 2.0.3
+ 2.0.4-SNAPSHOTjarmybatis-spring
@@ -80,7 +80,7 @@
http://github.com/mybatis/springscm:git:ssh://github.com/mybatis/spring.gitscm:git:ssh://git@github.com/mybatis/spring.git
- mybatis-spring-2.0.3
+ HEADGitHub Issue Management
From 7356e2ee6836cd009d9f3b5e89ff7c11b353a1e8 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sun, 20 Oct 2019 22:38:28 +0900
Subject: [PATCH 149/933] Support openjdk13 on Travis CI Fixes gh-407
---
.travis.yml | 1 +
pom.xml | 3 +++
2 files changed, 4 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 982f8be0ac..5f0793f150 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,7 @@
language: java
jdk:
+ - openjdk13
- openjdk12
- openjdk11
- openjdk8
diff --git a/pom.xml b/pom.xml
index 2073f9a26b..2322044692 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,9 @@
org.mybatis.spring5.5.0
+
+
+ 0.8.4
From e62fa0f73139ab10e3e3b8b13b945bcb79d43f53 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 21 Oct 2019 00:36:31 +0900
Subject: [PATCH 150/933] Support openjdk-ea on Travis CI Fixes gh-386
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index 5f0793f150..e69d708a09 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,7 @@
language: java
jdk:
+ - openjdk-ea
- openjdk13
- openjdk12
- openjdk11
From 7889c9810a399d9615ad90b6758d8207e4a5d7e5 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Sun, 10 Nov 2019 08:33:56 +0000
Subject: [PATCH 151/933] Bump hsqldb from 2.4.1 to 2.5.0
Bumps hsqldb from 2.4.1 to 2.5.0.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 2322044692..ca1db1d36b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -212,7 +212,7 @@
org.hsqldbhsqldb
- 2.4.1
+ 2.5.0test
From 1edf5b9ba64dfdc60827dbfebfda76060314d6e1 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Sun, 10 Nov 2019 08:35:05 +0000
Subject: [PATCH 152/933] Bump jakarta.transaction-api from 1.3.2 to 1.3.3
Bumps [jakarta.transaction-api](https://github.com/eclipse-ee4j/jta-api) from 1.3.2 to 1.3.3.
- [Release notes](https://github.com/eclipse-ee4j/jta-api/releases)
- [Commits](https://github.com/eclipse-ee4j/jta-api/compare/1.3.2...1.3.3)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 2322044692..de778f9044 100644
--- a/pom.xml
+++ b/pom.xml
@@ -297,7 +297,7 @@
jakarta.transactionjakarta.transaction-api
- 1.3.2
+ 1.3.3test
From ab901a5d33c40e04e60e0d177657c5dc8c76958e Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Sun, 10 Nov 2019 08:35:25 +0000
Subject: [PATCH 153/933] Bump jakarta.servlet-api from 4.0.2 to 4.0.3
Bumps [jakarta.servlet-api](https://github.com/eclipse-ee4j/servlet-api) from 4.0.2 to 4.0.3.
- [Release notes](https://github.com/eclipse-ee4j/servlet-api/releases)
- [Commits](https://github.com/eclipse-ee4j/servlet-api/commits)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 2322044692..1581a1f379 100644
--- a/pom.xml
+++ b/pom.xml
@@ -303,7 +303,7 @@
jakarta.servletjakarta.servlet-api
- 4.0.2
+ 4.0.3test
From 5cb0cf423973b44b3ad95bc518ee1e6a1c502c1f Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 11 Nov 2019 00:05:36 +0900
Subject: [PATCH 154/933] Upgrade to spring-framework 5.1.11 Fixes gh-417
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 0b96fcc650..4fc7bfe49e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.3
- 5.1.10.RELEASE
+ 5.1.11.RELEASE4.1.2.RELEASEorg.mybatis.spring
From 6f26832afdda625cd933cc99f58a5840622fbc6c Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Mon, 11 Nov 2019 00:08:52 +0900
Subject: [PATCH 155/933] Upgrade to spring-framework 5.2.1 on Travis CI Fixes
gh-418
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index e69d708a09..42b8fe9c89 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,7 @@ jdk:
script:
- ./mvnw clean verify
- - ./mvnw clean verify -Dspring.version=5.2.0.RELEASE -Dspring-batch.version=4.2.0.RELEASE -Denforcer.fail=false
+ - ./mvnw clean verify -Dspring.version=5.2.1.RELEASE -Dspring-batch.version=4.2.0.RELEASE -Denforcer.fail=false
after_success:
- chmod -R 777 ./travis/after_success.sh
From 91069f7ecdea3e07e1e950fe14afc4761ed19c80 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 11 Nov 2019 09:52:32 +0000
Subject: [PATCH 156/933] Bump mockito-core from 2.27.0 to 3.1.0
Bumps [mockito-core](https://github.com/mockito/mockito) from 2.27.0 to 3.1.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v2.27.0...v3.1.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4fc7bfe49e..01f06e9e1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -226,7 +226,7 @@
org.mockitomockito-core
- 2.27.0
+ 3.1.0test
From 48c9fde31188a03bef2d6d5bfe58b1d16706b48b Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 11 Nov 2019 09:53:23 +0000
Subject: [PATCH 157/933] Bump byteman-bmunit from 4.0.6 to 4.0.8
Bumps byteman-bmunit from 4.0.6 to 4.0.8.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4fc7bfe49e..793fe76979 100644
--- a/pom.xml
+++ b/pom.xml
@@ -171,7 +171,7 @@
org.jboss.bytemanbyteman-bmunit
- 4.0.6
+ 4.0.8test
From 7030348b2946b2d281e8242dcbea96e6a8a4d764 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 11 Nov 2019 09:54:19 +0000
Subject: [PATCH 158/933] Bump junit-jupiter-engine from 5.5.0 to 5.5.2
Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.5.0 to 5.5.2.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.5.0...r5.5.2)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4fc7bfe49e..7e34cd1819 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,7 +110,7 @@
4.1.2.RELEASEorg.mybatis.spring
- 5.5.0
+ 5.5.20.8.4
From 4158a0670a9ebdfaf5246f03fe3b371f525acc20 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Tue, 12 Nov 2019 06:57:31 +0000
Subject: [PATCH 159/933] Bump assertj-core from 3.12.2 to 3.14.0
Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.12.2 to 3.14.0.
- [Release notes](https://github.com/joel-costigliola/assertj-core/releases)
- [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.12.2...assertj-core-3.14.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c52a902b01..ec75aa08a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -233,7 +233,7 @@
org.assertjassertj-core
- 3.12.2
+ 3.14.0test
From ae1198602cef77748d96b816e95407a7f25af067 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Wed, 13 Nov 2019 01:54:40 +0900
Subject: [PATCH 160/933] Bump transactions-jdbc from 4.0.6 to 5.0.3 Fixes
gh-420
---
pom.xml | 2 +-
.../mybatis/spring/submitted/xa/applicationContext.xml | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index cb34d79e66..010a055400 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,7 +150,7 @@
com.atomikostransactions-jdbc
- 4.0.6
+ 5.0.3test
diff --git a/src/test/java/org/mybatis/spring/submitted/xa/applicationContext.xml b/src/test/java/org/mybatis/spring/submitted/xa/applicationContext.xml
index a8739f70dd..0e6098cdb3 100644
--- a/src/test/java/org/mybatis/spring/submitted/xa/applicationContext.xml
+++ b/src/test/java/org/mybatis/spring/submitted/xa/applicationContext.xml
@@ -47,11 +47,11 @@
-
-
@@ -78,6 +78,7 @@
init-method="init" destroy-method="close">
+ 1
@@ -96,6 +97,7 @@
init-method="init" destroy-method="close">
+ 1
@@ -146,4 +148,4 @@
-
+
From afcce3d1a3da43c2b0400ddde41d2d88bb7b554e Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Tue, 19 Nov 2019 07:04:48 +0000
Subject: [PATCH 161/933] Bump byteman-bmunit from 4.0.8 to 4.0.9
Bumps byteman-bmunit from 4.0.8 to 4.0.9.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 010a055400..7ecdc0b2b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -171,7 +171,7 @@
org.jboss.bytemanbyteman-bmunit
- 4.0.8
+ 4.0.9test
From de2dd1827c67be2f4775d6199001b0a3996c18a4 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 2 Dec 2019 06:59:21 +0000
Subject: [PATCH 162/933] Bump mockito-core from 3.1.0 to 3.2.0
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v3.1.0...v3.2.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7ecdc0b2b7..5b1631d663 100644
--- a/pom.xml
+++ b/pom.xml
@@ -226,7 +226,7 @@
org.mockitomockito-core
- 3.1.0
+ 3.2.0test
From 9d62e0cc56e7bd7cc56e3b99680c37c7b6890966 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 2 Dec 2019 06:59:43 +0000
Subject: [PATCH 163/933] Bump transactions-jdbc from 5.0.3 to 5.0.4
Bumps transactions-jdbc from 5.0.3 to 5.0.4.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7ecdc0b2b7..a6634c0f85 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,7 +150,7 @@
com.atomikostransactions-jdbc
- 5.0.3
+ 5.0.4test
From 35fbf55ad9c175e4f5087dc6bdf225abfbc6d103 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Tue, 3 Dec 2019 02:09:07 +0900
Subject: [PATCH 164/933] Revert "Remove unnecessary throws clause"
This reverts commit 5ca5f2df3577f8b670292cfb0864a57e9b8685e6.
---
src/main/java/org/mybatis/spring/SqlSessionTemplate.java | 4 ++--
.../org/mybatis/spring/batch/MyBatisCursorItemReader.java | 4 ++--
.../mybatis/spring/transaction/SpringManagedTransaction.java | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java
index f573d6317e..7f11156f6f 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java
@@ -389,7 +389,7 @@ public List flushStatements() {
/**
* Allow gently dispose bean:
- *
+ *
*
* {@code
*
@@ -407,7 +407,7 @@ public List flushStatements() {
* @see "org.springframework.beans.factory.support.DisposableBeanAdapter#CLOSE_METHOD_NAME"
*/
@Override
- public void destroy() {
+ public void destroy() throws Exception {
// This method forces spring disposer to avoid call of SqlSessionTemplate.close() which gives
// UnsupportedOperationException
}
diff --git a/src/main/java/org/mybatis/spring/batch/MyBatisCursorItemReader.java b/src/main/java/org/mybatis/spring/batch/MyBatisCursorItemReader.java
index a1527a7f4c..ee2626cce7 100644
--- a/src/main/java/org/mybatis/spring/batch/MyBatisCursorItemReader.java
+++ b/src/main/java/org/mybatis/spring/batch/MyBatisCursorItemReader.java
@@ -50,7 +50,7 @@ public MyBatisCursorItemReader() {
}
@Override
- protected T doRead() {
+ protected T doRead() throws Exception {
T next = null;
if (cursorIterator.hasNext()) {
next = cursorIterator.next();
@@ -59,7 +59,7 @@ protected T doRead() {
}
@Override
- protected void doOpen() {
+ protected void doOpen() throws Exception {
Map parameters = new HashMap<>();
if (parameterValues != null) {
parameters.putAll(parameterValues);
diff --git a/src/main/java/org/mybatis/spring/transaction/SpringManagedTransaction.java b/src/main/java/org/mybatis/spring/transaction/SpringManagedTransaction.java
index 32cb92146b..6d90052cd9 100644
--- a/src/main/java/org/mybatis/spring/transaction/SpringManagedTransaction.java
+++ b/src/main/java/org/mybatis/spring/transaction/SpringManagedTransaction.java
@@ -111,7 +111,7 @@ public void rollback() throws SQLException {
* {@inheritDoc}
*/
@Override
- public void close() {
+ public void close() throws SQLException {
DataSourceUtils.releaseConnection(this.connection, this.dataSource);
}
@@ -119,7 +119,7 @@ public void close() {
* {@inheritDoc}
*/
@Override
- public Integer getTimeout() {
+ public Integer getTimeout() throws SQLException {
ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
if (holder != null && holder.hasTimeout()) {
return holder.getTimeToLiveInSeconds();
From 76946c55bcd8e6c8f99a50c95c3989b2b420b9d8 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 4 Dec 2019 06:53:52 +0000
Subject: [PATCH 165/933] Bump spring.version from 5.1.11.RELEASE to
5.2.2.RELEASE
Bumps `spring.version` from 5.1.11.RELEASE to 5.2.2.RELEASE.
Updates `spring-context` from 5.1.11.RELEASE to 5.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.1.11.RELEASE...v5.2.2.RELEASE)
Updates `spring-jdbc` from 5.1.11.RELEASE to 5.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.1.11.RELEASE...v5.2.2.RELEASE)
Updates `spring-test` from 5.1.11.RELEASE to 5.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.1.11.RELEASE...v5.2.2.RELEASE)
Updates `spring-web` from 5.1.11.RELEASE to 5.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.1.11.RELEASE...v5.2.2.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 966fd1d55f..3ec1d8cc50 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.3
- 5.1.11.RELEASE
+ 5.2.2.RELEASE4.1.2.RELEASEorg.mybatis.spring
From 0ba4237fa50e62012c624d592cee158c3307b53e Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Fri, 6 Dec 2019 02:31:22 +0000
Subject: [PATCH 166/933] Bump spring-batch.version from 4.1.2.RELEASE to
4.2.1.RELEASE
Bumps `spring-batch.version` from 4.1.2.RELEASE to 4.2.1.RELEASE.
Updates `spring-batch-infrastructure` from 4.1.2.RELEASE to 4.2.1.RELEASE
- [Release notes](https://github.com/spring-projects/spring-batch/releases)
- [Commits](https://github.com/spring-projects/spring-batch/compare/4.1.2.RELEASE...4.2.1.RELEASE)
Updates `spring-batch-core` from 4.1.2.RELEASE to 4.2.1.RELEASE
- [Release notes](https://github.com/spring-projects/spring-batch/releases)
- [Commits](https://github.com/spring-projects/spring-batch/compare/4.1.2.RELEASE...4.2.1.RELEASE)
Updates `spring-batch-test` from 4.1.2.RELEASE to 4.2.1.RELEASE
- [Release notes](https://github.com/spring-projects/spring-batch/releases)
- [Commits](https://github.com/spring-projects/spring-batch/compare/4.1.2.RELEASE...4.2.1.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 3ec1d8cc50..329f0822cb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,7 +107,7 @@
3.5.35.2.2.RELEASE
- 4.1.2.RELEASE
+ 4.2.1.RELEASEorg.mybatis.spring5.5.2
From 6ec8be05e64b7043b3619923dc155decca595774 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Fri, 6 Dec 2019 11:44:11 +0900
Subject: [PATCH 167/933] Change version to spring 5.1.x and spring-batch 4.1.x
on Travis CI Fixes gh-434
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 42b8fe9c89..76074e2dbb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,7 @@ jdk:
script:
- ./mvnw clean verify
- - ./mvnw clean verify -Dspring.version=5.2.1.RELEASE -Dspring-batch.version=4.2.0.RELEASE -Denforcer.fail=false
+ - ./mvnw clean verify -Dspring.version=5.1.12.RELEASE -Dspring-batch.version=4.1.3.RELEASE
after_success:
- chmod -R 777 ./travis/after_success.sh
From cbfea6642bfa1ecb1bc82cc1140e5fc8a59813d3 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 9 Dec 2019 07:02:28 +0000
Subject: [PATCH 168/933] Bump transactions-jdbc from 5.0.4 to 5.0.5
Bumps transactions-jdbc from 5.0.4 to 5.0.5.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 329f0822cb..e492cae503 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,7 +150,7 @@
com.atomikostransactions-jdbc
- 5.0.4
+ 5.0.5test
From 94ac8c6ba99b8a6277278b07a4f4de188f8cd287 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Thu, 12 Dec 2019 06:53:36 +0000
Subject: [PATCH 169/933] Bump transactions-jdbc from 5.0.5 to 5.0.6
Bumps transactions-jdbc from 5.0.5 to 5.0.6.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e492cae503..34a6f0dfdb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,7 +150,7 @@
com.atomikostransactions-jdbc
- 5.0.5
+ 5.0.6test
From aa5de2fd65dd4a21c77718821803dbe11d6d1c35 Mon Sep 17 00:00:00 2001
From: Tatsuya Shimoda
Date: Thu, 12 Dec 2019 17:02:19 +0900
Subject: [PATCH 170/933] Scan mappers from the package of the class that
declares MapperScan annotation if basePackages attrubute is not present
---
.../org/mybatis/spring/annotation/MapperScan.java | 5 +++++
.../spring/annotation/MapperScannerRegistrar.java | 14 +++++++++++---
.../mybatis/spring/annotation/MapperScanTest.java | 14 ++++++++++++++
.../mapper/AppConfigWithDefaultPackageScan.java | 10 ++++++++++
4 files changed, 40 insertions(+), 3 deletions(-)
create mode 100644 src/test/java/org/mybatis/spring/mapper/AppConfigWithDefaultPackageScan.java
diff --git a/src/main/java/org/mybatis/spring/annotation/MapperScan.java b/src/main/java/org/mybatis/spring/annotation/MapperScan.java
index ee587e1775..8be5d010a6 100644
--- a/src/main/java/org/mybatis/spring/annotation/MapperScan.java
+++ b/src/main/java/org/mybatis/spring/annotation/MapperScan.java
@@ -31,6 +31,11 @@
/**
* Use this annotation to register MyBatis mapper interfaces when using Java Config. It performs when same work as
* {@link MapperScannerConfigurer} via {@link MapperScannerRegistrar}.
+ *
+ *
Either {@link #basePackageClasses} or {@link #basePackages} (or its alias
+ * {@link #value}) may be specified to define specific packages to scan. If specific
+ * packages are not defined, scanning will occur from the package of the
+ * class that declares this annotation.
*
*
Either {@link #basePackageClasses} or {@link #basePackages} (or its alias
- * {@link #value}) may be specified to define specific packages to scan. If specific
- * packages are not defined, scanning will occur from the package of the
- * class that declares this annotation.
+ * {@link #value}) may be specified to define specific packages to scan.
+ * Since 2.0.4, If specific packages are not defined, scanning will occur from
+ * the package of the class that declares this annotation.
*
*
* Configuration example:
diff --git a/src/test/java/org/mybatis/spring/annotation/MapperScanTest.java b/src/test/java/org/mybatis/spring/annotation/MapperScanTest.java
index 6ef2286712..0b54054a0c 100644
--- a/src/test/java/org/mybatis/spring/annotation/MapperScanTest.java
+++ b/src/test/java/org/mybatis/spring/annotation/MapperScanTest.java
@@ -26,6 +26,8 @@
import org.junit.jupiter.api.Test;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.mapper.ds1.AppConfigWithDefaultMapperScanAndRepeat;
+import org.mybatis.spring.annotation.mapper.ds1.AppConfigWithDefaultMapperScans;
import org.mybatis.spring.annotation.mapper.ds1.Ds1Mapper;
import org.mybatis.spring.mapper.AnnotatedMapper;
import org.mybatis.spring.mapper.AppConfigWithDefaultPackageScan;
@@ -289,6 +291,32 @@ void testScanWithMapperScans() {
applicationContext.getBean("ds2Mapper");
}
+ @Test
+ void testScanWithDefaultMapperScanAndRepeat() {
+ applicationContext.register(AppConfigWithDefaultMapperScanAndRepeat.class);
+
+ startContext();
+
+ SqlSessionFactory sqlSessionFactory = applicationContext.getBean(SqlSessionFactory.class);
+ assertEquals(2, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size());
+
+ applicationContext.getBean("ds1Mapper");
+ applicationContext.getBean("ds2Mapper");
+ }
+
+ @Test
+ void testScanWithDefaultMapperScans() {
+ applicationContext.register(AppConfigWithDefaultMapperScans.class);
+
+ startContext();
+
+ SqlSessionFactory sqlSessionFactory = applicationContext.getBean(SqlSessionFactory.class);
+ assertEquals(2, sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers().size());
+
+ applicationContext.getBean("ds1Mapper");
+ applicationContext.getBean("ds2Mapper");
+ }
+
@Test
void testLazyScanWithPropertySourcesPlaceholderConfigurer() {
applicationContext.register(LazyConfigWithPropertySourcesPlaceholderConfigurer.class);
diff --git a/src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScanAndRepeat.java b/src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScanAndRepeat.java
new file mode 100644
index 0000000000..a6edbcad18
--- /dev/null
+++ b/src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScanAndRepeat.java
@@ -0,0 +1,10 @@
+package org.mybatis.spring.annotation.mapper.ds1;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@MapperScan
+@MapperScan("org.mybatis.spring.annotation.mapper.ds2")
+public class AppConfigWithDefaultMapperScanAndRepeat {
+}
diff --git a/src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScans.java b/src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScans.java
new file mode 100644
index 0000000000..af3e1364f7
--- /dev/null
+++ b/src/test/java/org/mybatis/spring/annotation/mapper/ds1/AppConfigWithDefaultMapperScans.java
@@ -0,0 +1,13 @@
+package org.mybatis.spring.annotation.mapper.ds1;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.mybatis.spring.annotation.MapperScans;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@MapperScans({
+ @MapperScan,
+ @MapperScan("org.mybatis.spring.annotation.mapper.ds2")
+})
+public class AppConfigWithDefaultMapperScans {
+}
From 33e568af40d68d5cff9ba86fa283514df8e3f4e3 Mon Sep 17 00:00:00 2001
From: shimoda
Date: Fri, 13 Dec 2019 12:18:05 +0900
Subject: [PATCH 172/933] added a note in the document
---
src/site/xdoc/mappers.xml | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/site/xdoc/mappers.xml b/src/site/xdoc/mappers.xml
index 304b6fecab..62fe64b118 100644
--- a/src/site/xdoc/mappers.xml
+++ b/src/site/xdoc/mappers.xml
@@ -247,7 +247,11 @@ public class AppConfig {
You can also provide an specific SqlSessionFactory or SqlSessionTemplate
by using its properties sqlSessionFactory and sqlSessionTemplate.
-
+
+
+ NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
+
+
MapperScannerConfigurer
From be079d6a0ab115883d604d15a7afdf71ca645f13 Mon Sep 17 00:00:00 2001
From: Tatsuya Shimoda
Date: Sat, 14 Dec 2019 03:17:28 +0900
Subject: [PATCH 173/933] added AnnotationAttributes as a param
---
.../mybatis/spring/annotation/MapperScannerRegistrar.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java b/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java
index e77167de5f..e9b1546365 100644
--- a/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java
+++ b/src/main/java/org/mybatis/spring/annotation/MapperScannerRegistrar.java
@@ -70,11 +70,11 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
AnnotationAttributes mapperScanAttrs = AnnotationAttributes
.fromMap(importingClassMetadata.getAnnotationAttributes(MapperScan.class.getName()));
if (mapperScanAttrs != null) {
- registerBeanDefinitions(mapperScanAttrs, registry, generateBaseBeanName(importingClassMetadata, 0), getDefaultBasePackage(importingClassMetadata));
+ registerBeanDefinitions(importingClassMetadata, mapperScanAttrs, registry, generateBaseBeanName(importingClassMetadata, 0));
}
}
- void registerBeanDefinitions(AnnotationAttributes annoAttrs, BeanDefinitionRegistry registry, String beanName, String defaultBasePackage) {
+ void registerBeanDefinitions(AnnotationMetadata annoMeta, AnnotationAttributes annoAttrs, BeanDefinitionRegistry registry, String beanName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
builder.addPropertyValue("processPropertyPlaceHolders", true);
@@ -120,7 +120,7 @@ void registerBeanDefinitions(AnnotationAttributes annoAttrs, BeanDefinitionRegis
.collect(Collectors.toList()));
if (basePackages.isEmpty()) {
- basePackages.add(defaultBasePackage);
+ basePackages.add(getDefaultBasePackage(annoMeta));
}
String lazyInitialization = annoAttrs.getString("lazyInitialization");
@@ -158,7 +158,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B
if (mapperScansAttrs != null) {
AnnotationAttributes[] annotations = mapperScansAttrs.getAnnotationArray("value");
for (int i = 0; i < annotations.length; i++) {
- registerBeanDefinitions(annotations[i], registry, generateBaseBeanName(importingClassMetadata, i), getDefaultBasePackage(importingClassMetadata));
+ registerBeanDefinitions(importingClassMetadata, annotations[i], registry, generateBaseBeanName(importingClassMetadata, i));
}
}
}
From a9fce71a747ff8773d2aa452b6ba8912098f3642 Mon Sep 17 00:00:00 2001
From: Tatsuya Shimoda
Date: Sat, 14 Dec 2019 03:39:11 +0900
Subject: [PATCH 174/933] added i18n docs
---
src/site/es/xdoc/mappers.xml | 6 +++++-
src/site/ja/xdoc/mappers.xml | 6 +++++-
src/site/ko/xdoc/mappers.xml | 6 +++++-
src/site/zh/xdoc/mappers.xml | 4 ++++
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/site/es/xdoc/mappers.xml b/src/site/es/xdoc/mappers.xml
index 0baebebce8..de81624425 100644
--- a/src/site/es/xdoc/mappers.xml
+++ b/src/site/es/xdoc/mappers.xml
@@ -234,7 +234,11 @@ public class AppConfig {
Tambien puedes indicar una SqlSessionFactory o un SqlSessionTemplate específicos
mediante las propiedades sqlSessionFactory y sqlSessionTemplate.
-
+
+
+ NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
+
diff --git a/src/site/ko/xdoc/mappers.xml b/src/site/ko/xdoc/mappers.xml
index 3a2acb6b30..08abb2e8de 100644
--- a/src/site/ko/xdoc/mappers.xml
+++ b/src/site/ko/xdoc/mappers.xml
@@ -191,7 +191,11 @@ public class AppConfig {
markerInterface 와 annotationClass 프로퍼티를 사용해서 마커 인터페이스와 애노테이션 클래스를 명시하게 한다.
sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 사용해서
SqlSessionFactory 나 SqlSessionTemplate을 제공할 수도 있다.
-
+
+
+ NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
+
+
MapperScannerConfigurer
MapperScannerConfigurer는 평범한 빈처럼 XML애플리케이션 컨텍스트에 포함된 BeanDefinitionRegistryPostProcessor 이다.
diff --git a/src/site/zh/xdoc/mappers.xml b/src/site/zh/xdoc/mappers.xml
index 34320c51b3..a426f640ce 100644
--- a/src/site/zh/xdoc/mappers.xml
+++ b/src/site/zh/xdoc/mappers.xml
@@ -195,6 +195,10 @@ public class AppConfig {
这个注解具有与之前见过的 <mybatis:scan/> 元素一样的工作方式。它也可以通过 markerInterface 和 annotationClass 属性设置标记接口或注解类。通过配置 sqlSessionFactory 和 sqlSessionTemplate 属性,你还能指定一个 SqlSessionFactory 或 SqlSessionTemplate。
+
+ NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
+
+
MapperScannerConfigurer
From bb33c660a1f7c1fb5b2adce1511d6666c5dc5a08 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Tue, 17 Dec 2019 06:59:43 +0000
Subject: [PATCH 175/933] Bump mockito-core from 3.2.0 to 3.2.4
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.2.0 to 3.2.4.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v3.2.0...v3.2.4)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 34a6f0dfdb..c26d4cfc65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -226,7 +226,7 @@
org.mockitomockito-core
- 3.2.0
+ 3.2.4test
From 782cbd66f920dc0cd282287c31249788d900df91 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 15 Jan 2020 06:57:51 +0000
Subject: [PATCH 176/933] Bump spring.version from 5.2.2.RELEASE to
5.2.3.RELEASE
Bumps `spring.version` from 5.2.2.RELEASE to 5.2.3.RELEASE.
Updates `spring-context` from 5.2.2.RELEASE to 5.2.3.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.2.RELEASE...v5.2.3.RELEASE)
Updates `spring-jdbc` from 5.2.2.RELEASE to 5.2.3.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.2.RELEASE...v5.2.3.RELEASE)
Updates `spring-test` from 5.2.2.RELEASE to 5.2.3.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.2.RELEASE...v5.2.3.RELEASE)
Updates `spring-web` from 5.2.2.RELEASE to 5.2.3.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.2.RELEASE...v5.2.3.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c26d4cfc65..4c6f8824fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.3
- 5.2.2.RELEASE
+ 5.2.3.RELEASE4.2.1.RELEASEorg.mybatis.spring
From 898005c6f5782f41e88efe3d8f6599b7833678d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BA=B7=E6=99=BA=E5=86=AC?=
Date: Mon, 20 Jan 2020 11:20:12 +0800
Subject: [PATCH 177/933] Fix typo
Fix typo
---
src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
index fb7463e168..0a374567f4 100644
--- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
+++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java
@@ -479,7 +479,7 @@ public void afterPropertiesSet() throws Exception {
* Build a {@code SqlSessionFactory} instance.
*
* The default implementation uses the standard MyBatis {@code XMLConfigBuilder} API to build a
- * {@code SqlSessionFactory} instance based on an Reader. Since 1.3.0, it can be specified a {@link Configuration}
+ * {@code SqlSessionFactory} instance based on a Reader. Since 1.3.0, it can be specified a {@link Configuration}
* instance directly(without config file).
*
* @return SqlSessionFactory
From b196c31d47d99f785da3c110728e2239803fc0e4 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Tue, 21 Jan 2020 06:57:08 +0000
Subject: [PATCH 178/933] Bump junit-jupiter-engine from 5.5.2 to 5.6.0
Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.5.2 to 5.6.0.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.5.2...r5.6.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4c6f8824fb..630835fcff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,7 +110,7 @@
4.2.1.RELEASEorg.mybatis.spring
- 5.5.2
+ 5.6.00.8.4
From 11c7c6b11b78a3fbdcf20cb1aca2ba365fbeaf00 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Tue, 21 Jan 2020 06:57:25 +0000
Subject: [PATCH 179/933] Bump byteman-bmunit from 4.0.9 to 4.0.10
Bumps byteman-bmunit from 4.0.9 to 4.0.10.
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 4c6f8824fb..17161c2387 100644
--- a/pom.xml
+++ b/pom.xml
@@ -171,7 +171,7 @@
org.jboss.bytemanbyteman-bmunit
- 4.0.9
+ 4.0.10test
From 9e2d93180ef3639c8ab99ae5179e80f3fd457b24 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 29 Jan 2020 07:00:50 +0000
Subject: [PATCH 180/933] Bump assertj-core from 3.14.0 to 3.15.0
Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.14.0 to 3.15.0.
- [Release notes](https://github.com/joel-costigliola/assertj-core/releases)
- [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.14.0...assertj-core-3.15.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index aa24050a8e..b071114702 100644
--- a/pom.xml
+++ b/pom.xml
@@ -233,7 +233,7 @@
org.assertjassertj-core
- 3.14.0
+ 3.15.0test
From 51f51b67bb31ac15b1a2f92178a6325eccebc827 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 3 Feb 2020 07:17:32 +0000
Subject: [PATCH 181/933] Bump mybatis from 3.5.3 to 3.5.4
Bumps [mybatis](https://github.com/mybatis/mybatis-3) from 3.5.3 to 3.5.4.
- [Release notes](https://github.com/mybatis/mybatis-3/releases)
- [Commits](https://github.com/mybatis/mybatis-3/compare/mybatis-3.5.3...mybatis-3.5.4)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b071114702..a742c95789 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,7 +105,7 @@
org.springframework.batch.*;resolution:=optional,**
- 3.5.3
+ 3.5.45.2.3.RELEASE4.2.1.RELEASEorg.mybatis.spring
From 04152591073807ce85d54ced0e6b848f02c15355 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 24 Feb 2020 07:02:35 +0000
Subject: [PATCH 182/933] Bump mockito-core from 3.2.4 to 3.3.0
Bumps [mockito-core](https://github.com/mockito/mockito) from 3.2.4 to 3.3.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](https://github.com/mockito/mockito/compare/v3.2.4...v3.3.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index a742c95789..747811a515 100644
--- a/pom.xml
+++ b/pom.xml
@@ -226,7 +226,7 @@
org.mockitomockito-core
- 3.2.4
+ 3.3.0test
From ce914b885cba7d44faa6222094f451bb8a3af894 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 26 Feb 2020 07:03:53 +0000
Subject: [PATCH 183/933] Bump spring.version from 5.2.3.RELEASE to
5.2.4.RELEASE
Bumps `spring.version` from 5.2.3.RELEASE to 5.2.4.RELEASE.
Updates `spring-context` from 5.2.3.RELEASE to 5.2.4.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.3.RELEASE...v5.2.4.RELEASE)
Updates `spring-jdbc` from 5.2.3.RELEASE to 5.2.4.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.3.RELEASE...v5.2.4.RELEASE)
Updates `spring-test` from 5.2.3.RELEASE to 5.2.4.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.3.RELEASE...v5.2.4.RELEASE)
Updates `spring-web` from 5.2.3.RELEASE to 5.2.4.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.3.RELEASE...v5.2.4.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 747811a515..8b6945b27d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.4
- 5.2.3.RELEASE
+ 5.2.4.RELEASE4.2.1.RELEASEorg.mybatis.spring
From 058e9219e85819063d53d1fa0a1f0f0bc0fe7eb0 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 7 Mar 2020 01:37:53 +0900
Subject: [PATCH 184/933] Drop openjdk12 on Travis CI Fixes gh-431
---
.travis.yml | 1 -
1 file changed, 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 76074e2dbb..e835448918 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,7 +3,6 @@ language: java
jdk:
- openjdk-ea
- openjdk13
- - openjdk12
- openjdk11
- openjdk8
From f9b954dd1ee0f0ff1a26ccfd69cf784fb24b1e5a Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 7 Mar 2020 01:38:17 +0900
Subject: [PATCH 185/933] Support openjdk14 on Travis CI Fixes gh-450
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index e835448918..d587f513cc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,6 +2,7 @@ language: java
jdk:
- openjdk-ea
+ - openjdk14
- openjdk13
- openjdk11
- openjdk8
From ec91145620faa9d4d1eef02c3c594f894a4e0bd0 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 7 Mar 2020 01:45:29 +0900
Subject: [PATCH 186/933] Update to spring-framework 5.1.14.RELEASE on Travis
CI Fixes gh-449
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index d587f513cc..77d622b6df 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,7 @@ jdk:
script:
- ./mvnw clean verify
- - ./mvnw clean verify -Dspring.version=5.1.12.RELEASE -Dspring-batch.version=4.1.3.RELEASE
+ - ./mvnw clean verify -Dspring.version=5.1.14.RELEASE -Dspring-batch.version=4.1.3.RELEASE
after_success:
- chmod -R 777 ./travis/after_success.sh
From 7b543476c8055e59b0628d8852af1900ef9c9ef5 Mon Sep 17 00:00:00 2001
From: Iwao AVE!
Date: Mon, 9 Mar 2020 01:07:07 +0900
Subject: [PATCH 187/933] License header and format
---
pom.xml | 2 +-
.../mybatis/spring/SqlSessionFactoryBean.java | 2 +-
.../mybatis/spring/annotation/MapperScan.java | 10 +++++-----
.../annotation/MapperScannerRegistrar.java | 11 ++++++----
...pConfigWithDefaultMapperScanAndRepeat.java | 15 ++++++++++++++
.../ds1/AppConfigWithDefaultMapperScans.java | 20 +++++++++++++++----
.../AppConfigWithDefaultPackageScan.java | 15 ++++++++++++++
.../org/mybatis/spring/scan/package-info.java | 2 +-
.../org/mybatis/spring/type/package-info.java | 2 +-
9 files changed, 62 insertions(+), 17 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8b6945b27d..351441e89e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
0.8.4
From bd48f0a7759348d006566844f1fc109b2c0f12ac Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 25 Mar 2020 06:56:52 +0000
Subject: [PATCH 203/933] Bump spring.version from 5.2.4.RELEASE to
5.2.5.RELEASE
Bumps `spring.version` from 5.2.4.RELEASE to 5.2.5.RELEASE.
Updates `spring-context` from 5.2.4.RELEASE to 5.2.5.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.4.RELEASE...v5.2.5.RELEASE)
Updates `spring-jdbc` from 5.2.4.RELEASE to 5.2.5.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.4.RELEASE...v5.2.5.RELEASE)
Updates `spring-test` from 5.2.4.RELEASE to 5.2.5.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.4.RELEASE...v5.2.5.RELEASE)
Updates `spring-web` from 5.2.4.RELEASE to 5.2.5.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.4.RELEASE...v5.2.5.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e614644bc9..52ccd02e35 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.4
- 5.2.4.RELEASE
+ 5.2.5.RELEASE4.2.1.RELEASEorg.mybatis.spring
From 9f5d65c686889096240e40f47c9f119066faed78 Mon Sep 17 00:00:00 2001
From: Kihwan Kim
Date: Tue, 31 Mar 2020 13:56:38 +0900
Subject: [PATCH 204/933] correct a mistranslation.
---
src/site/ko/xdoc/mappers.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/site/ko/xdoc/mappers.xml b/src/site/ko/xdoc/mappers.xml
index 08abb2e8de..8dda92e451 100644
--- a/src/site/ko/xdoc/mappers.xml
+++ b/src/site/ko/xdoc/mappers.xml
@@ -29,7 +29,7 @@
-
데이터 접근 객체인 DAO를 만든것보다 직접 SqlSessionDaoSupport 나 SqlSessionTemplate 를 사용하자.
+
SqlSessionDaoSupport 나 SqlSessionTemplate 를 직접적으로 사용하는 데이터 접근 객체(DAO)를 생성하기 보다,
마이바티스 스프링 연동모듈은 다른 빈에 직접 주입할 수 있는 쓰레드에 안전한 매퍼를 생성할 수 있다.
From 51dadd4962b41a6a60a625fe270116b5e16f02e3 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Thu, 2 Apr 2020 06:54:47 +0000
Subject: [PATCH 205/933] Bump spring-batch.version from 4.2.1.RELEASE to
4.2.2.RELEASE
Bumps `spring-batch.version` from 4.2.1.RELEASE to 4.2.2.RELEASE.
Updates `spring-batch-infrastructure` from 4.2.1.RELEASE to 4.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-batch/releases)
- [Commits](https://github.com/spring-projects/spring-batch/compare/4.2.1.RELEASE...4.2.2.RELEASE)
Updates `spring-batch-core` from 4.2.1.RELEASE to 4.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-batch/releases)
- [Commits](https://github.com/spring-projects/spring-batch/compare/4.2.1.RELEASE...4.2.2.RELEASE)
Updates `spring-batch-test` from 4.2.1.RELEASE to 4.2.2.RELEASE
- [Release notes](https://github.com/spring-projects/spring-batch/releases)
- [Commits](https://github.com/spring-projects/spring-batch/compare/4.2.1.RELEASE...4.2.2.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 52ccd02e35..6bfa1232e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,7 +107,7 @@
3.5.45.2.5.RELEASE
- 4.2.1.RELEASE
+ 4.2.2.RELEASEorg.mybatis.spring5.6.1
From c421a611870177a9a90b896a2fcfbd763d8cec24 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 29 Apr 2020 06:59:45 +0000
Subject: [PATCH 206/933] Bump spring.version from 5.2.5.RELEASE to
5.2.6.RELEASE
Bumps `spring.version` from 5.2.5.RELEASE to 5.2.6.RELEASE.
Updates `spring-context` from 5.2.5.RELEASE to 5.2.6.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.5.RELEASE...v5.2.6.RELEASE)
Updates `spring-jdbc` from 5.2.5.RELEASE to 5.2.6.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.5.RELEASE...v5.2.6.RELEASE)
Updates `spring-test` from 5.2.5.RELEASE to 5.2.6.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.5.RELEASE...v5.2.6.RELEASE)
Updates `spring-web` from 5.2.5.RELEASE to 5.2.6.RELEASE
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v5.2.5.RELEASE...v5.2.6.RELEASE)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 6bfa1232e2..6c994bf27e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,7 +106,7 @@
*3.5.4
- 5.2.5.RELEASE
+ 5.2.6.RELEASE4.2.2.RELEASEorg.mybatis.spring
From 853678c591d18c16249ac545cdfca8f9ade79e1c Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Wed, 6 May 2020 06:54:47 +0000
Subject: [PATCH 207/933] Bump assertj-core from 3.15.0 to 3.16.0
Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.15.0 to 3.16.0.
- [Release notes](https://github.com/joel-costigliola/assertj-core/releases)
- [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.15.0...assertj-core-3.16.0)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 6c994bf27e..c6ba46fc11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -233,7 +233,7 @@
org.assertjassertj-core
- 3.15.0
+ 3.16.0test
From a18fccd390a506a422d91c1356d70b98c1188555 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Mon, 11 May 2020 07:20:11 +0000
Subject: [PATCH 208/933] Bump assertj-core from 3.16.0 to 3.16.1
Bumps [assertj-core](https://github.com/joel-costigliola/assertj-core) from 3.16.0 to 3.16.1.
- [Release notes](https://github.com/joel-costigliola/assertj-core/releases)
- [Commits](https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.16.0...assertj-core-3.16.1)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c6ba46fc11..680d671972 100644
--- a/pom.xml
+++ b/pom.xml
@@ -233,7 +233,7 @@
org.assertjassertj-core
- 3.16.0
+ 3.16.1test
From 9a52735f1c3d41b51bcab0c3ee538b5f630e1d72 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sun, 17 May 2020 12:46:09 +0900
Subject: [PATCH 209/933] Prevent build error of maven-bundle-pluin on JDK 15
---
.travis.yml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 77d622b6df..2036f1ce50 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,10 @@ jdk:
- openjdk11
- openjdk8
+jobs:
+ allow_failures:
+ - jdk: openjdk-ea
+
script:
- ./mvnw clean verify
- ./mvnw clean verify -Dspring.version=5.1.14.RELEASE -Dspring-batch.version=4.1.3.RELEASE
From 5deee32a2d8113794797dd364fb7cc2a8afd0cb5 Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Sun, 17 May 2020 03:52:43 +0000
Subject: [PATCH 210/933] Bump junit-jupiter-engine from 5.6.1 to 5.6.2
Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.6.1 to 5.6.2.
- [Release notes](https://github.com/junit-team/junit5/releases)
- [Commits](https://github.com/junit-team/junit5/compare/r5.6.1...r5.6.2)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 680d671972..4a03cff574 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,7 +110,7 @@
4.2.2.RELEASEorg.mybatis.spring
- 5.6.1
+ 5.6.20.8.4
From a15f145a2a4ffe92a224c9efa7f557cc767a0b24 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sun, 17 May 2020 13:34:49 +0900
Subject: [PATCH 211/933] Add comment for preventing fail maven-bundle-plugin
on JDK 15
---
.travis.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.travis.yml b/.travis.yml
index 2036f1ce50..a4e80eaa96 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,6 +9,7 @@ jdk:
jobs:
allow_failures:
+ # Fail maven-bundle-plugin on JDK 15 (https://issues.apache.org/jira/browse/FELIX-6259,https://github.com/mybatis/parent/issues/160)
- jdk: openjdk-ea
script:
From a01d1953604cca224727baea5557b952bbc2b122 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Fri, 5 Jun 2020 04:06:49 +0900
Subject: [PATCH 212/933] Update license year
---
src/site/ko/xdoc/mappers.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/site/ko/xdoc/mappers.xml b/src/site/ko/xdoc/mappers.xml
index 8dda92e451..a6152928c9 100644
--- a/src/site/ko/xdoc/mappers.xml
+++ b/src/site/ko/xdoc/mappers.xml
@@ -1,7 +1,7 @@
- 0.8.4
@@ -359,4 +357,12 @@
+
+
+ sonatype-oss-snapshots
+ Sonatype OSS Snapshots Repository
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+
From bf3d14794e25a79a59cc45ec62f1f93d2f5b63ec Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sat, 13 Jun 2020 18:42:51 +0900
Subject: [PATCH 222/933] Apply latest version of Spring 5.1.x and Spring Batch
4.1.x automatically on Travis CI
---
.travis.yml | 2 +-
travis/get_latest_version.sh | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100755 travis/get_latest_version.sh
diff --git a/.travis.yml b/.travis.yml
index 4f9073985f..d8110f766a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,7 +8,7 @@ jdk:
script:
- ./mvnw clean verify
- - ./mvnw clean verify -Dspring.version=5.1.15.RELEASE -Dspring-batch.version=4.1.4.RELEASE
+ - ./mvnw clean verify -Dspring.version=$(./travis/get_latest_version.sh spring-core 5.1) -Dspring-batch.version=$(./travis/get_latest_version.sh batch/spring-batch-core 4.1)
after_success:
- chmod -R 777 ./travis/after_success.sh
diff --git a/travis/get_latest_version.sh b/travis/get_latest_version.sh
new file mode 100755
index 0000000000..608eaa42a5
--- /dev/null
+++ b/travis/get_latest_version.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Copyright 2010-2020 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+targetArtifact=$1
+targetMinorVersion=$2
+majorVersion=${targetMinorVersion%.*}
+minorVersion=${targetMinorVersion#*.}
+while read -r line; do
+ maintenanceVersion=${line#${targetMinorVersion}.} && maintenanceVersion=${maintenanceVersion%%.*}
+ maintenanceVersions="${maintenanceVersions}${maintenanceVersion}"$'\n'
+done<${majorVersion}\.${minorVersion}\.[0-9]*")
+END
+echo "${targetMinorVersion}.$(echo "${maintenanceVersions}" | sort -n | tail -n 1).RELEASE"
From 374a62eb5063a3dd5e6dcaeafdbe402366a65909 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Sun, 21 Jun 2020 14:05:05 +0900
Subject: [PATCH 223/933] Support scoped proxy on mapper scan feature Fixes
gh-476
---
.../mybatis/spring/annotation/MapperScan.java | 18 +++-
.../annotation/MapperScannerRegistrar.java | 10 ++-
.../MapperScannerBeanDefinitionParser.java | 12 +--
.../spring/mapper/ClassPathMapperScanner.java | 65 ++++++++++++--
.../mapper/MapperScannerConfigurer.java | 21 +++++
.../mybatis/spring/config/mybatis-spring.xsd | 11 ++-
.../spring/annotation/MapperScanTest.java | 50 ++++++++++-
.../annotation/mapper/ds1/Ds1Mapper.java | 5 +-
.../annotation/mapper/ds2/Ds2Mapper.java | 8 +-
.../mybatis/spring/config/NamespaceTest.java | 58 +++++++++++--
.../spring/config/default-scope.properties | 17 ++++
.../mybatis/spring/config/default-scope.xml | 39 +++++++++
.../spring/mapper/AnnotatedMapper.java | 7 +-
.../mapper/MapperScannerConfigurerTest.java | 87 ++++++++++++++++++-
.../spring/mapper/ScopedProxyMapper.java | 28 ++++++
15 files changed, 401 insertions(+), 35 deletions(-)
create mode 100644 src/test/java/org/mybatis/spring/config/default-scope.properties
create mode 100644 src/test/java/org/mybatis/spring/config/default-scope.xml
create mode 100644 src/test/java/org/mybatis/spring/mapper/ScopedProxyMapper.java
diff --git a/src/main/java/org/mybatis/spring/annotation/MapperScan.java b/src/main/java/org/mybatis/spring/annotation/MapperScan.java
index 2d8e7d1c3e..ebeed88007 100644
--- a/src/main/java/org/mybatis/spring/annotation/MapperScan.java
+++ b/src/main/java/org/mybatis/spring/annotation/MapperScan.java
@@ -25,13 +25,14 @@
import org.mybatis.spring.mapper.MapperFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.Import;
/**
* Use this annotation to register MyBatis mapper interfaces when using Java Config. It performs when same work as
* {@link MapperScannerConfigurer} via {@link MapperScannerRegistrar}.
- *
+ *
*
- NOTE<context:component-scan/>
+ NOTE<context:component-scan/>
no puede encontrar y registrar mappers. Los mappers son interfaces y, para poderlos registrar en Spring,
el scanner deben conocer cómo crear un MapperFactoryBean para cada interfaz encontrado.
@MapperScan
-
+
- Si usas la Java Configuration de Spring (@Configuration) posiblemente prefieras usar
- @MapperScan en lugar de <mybatis:scan/>.
+ Si usas la Java Configuration de Spring (@Configuration) posiblemente prefieras usar
+ @MapperScan en lugar de <mybatis:scan/>.
-
+
La anotación @MapperScan se usa de la siguiente forma:
-
+
-
+
La anotación fucniona exactamente igual que <mybatis:scan/> que hemos visto en la sección anterior.
- También te permite especificar un interfaz marcador o una anotación mediante sus propiedades
- markerInterface y annotationClass.
+ También te permite especificar un interfaz marcador o una anotación mediante sus propiedades
+ markerInterface y annotationClass.
Tambien puedes indicar una SqlSessionFactory o un SqlSessionTemplate específicos
mediante las propiedades sqlSessionFactory y sqlSessionTemplate.
@@ -240,9 +249,9 @@ public class AppConfig {
MapperScannerConfigurer
-
+
- MapperScannerConfigurer es un BeanDefinitionRegistryPostProcessor
+ MapperScannerConfigurer es un BeanDefinitionRegistryPostProcessor
que se puede incluir como un bean normal en el fichero clásico XML de configuración de Spring.
Para configurar un MapperScannerConfigurer añade lo siguiente al fichero de configuración de Spring:
@@ -256,7 +265,7 @@ public class AppConfig {
por ello se usa el atributo value en lugar del habitual ref:
이 코드를 보면 SqlSession이나 마이바티스 객체가 보이지 않는다.
- 게다가 세션을 생성하거나 열고 닫을필요도 없어보인다.
+
이 코드를 보면 SqlSession이나 마이바티스 객체가 보이지 않는다.
+ 게다가 세션을 생성하거나 열고 닫을필요도 없어보인다.
마이바티스 스프링 연동모듈이 알아서 처리할 것이다.
매퍼를 등록하는 방법은 기존의 전통적인 XML설정법을 사용하거나 새로운 3.0 이후의 자바설정(일명 @Configuration)을 사용하느냐에 따라 다르다.
-
+
XML설정 사용
-
+
매퍼는 다음처럼 XML설정파일에 MapperFactoryBean을 두는 것으로 스프링에 등록된다.
@@ -68,13 +68,13 @@
매퍼 XML파일을 다른 클래스패스에 두는게 아니라면 마이바티스 설정파일에 매퍼를 지정할 필요가 없다.
좀더 세부적인 정보는 SqlSessionFactoryBean의 configLocation 프로퍼티를 살펴보자.
-
MapperFactoryBean은 SqlSessionFactory 나 SqlSessionTemplate가 필요하다.
- sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 셋팅하면 된다.
- 둘다 셋팅하면 SqlSessionFactory가 무시된다.
+
MapperFactoryBean은 SqlSessionFactory 나 SqlSessionTemplate가 필요하다.
+ sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 셋팅하면 된다.
+ 둘다 셋팅하면 SqlSessionFactory가 무시된다.
세션 팩토리 셋은 SqlSessionTemplate이 필요하고 MapperFactoryBean는 팩토리를 사용할것이다.
+ Since 2.0.6, the develop become can specified scope of mapper using mapper scanning feature option(default-scope)
+ and scope annotation(@Scope, @RefreshScope, etc ...).
+ The motivation for adding this option is supporting the refresh scope provided by the Spring Cloud.
+ The default of this option is empty (= equiv to specify the singleton scope).
+ The default-scope apply to the mapper bean(MapperFactoryBean) when scope of scanned bean definition
+ is singleton(default scope) and create a scoped proxy bean for scanned mapper when final scope is not singleton.
+
+
<mybatis:scan/>
-
+
<mybatis:scan/> XML엘리먼트는 스프링에서 제공하는 <context:component-scan/> 엘리먼트와 매우 유사한 방법으로 매퍼를 검색할 것이다.
-
+
샘플 XML설정을 아래에서 볼수 있다.
-
+
]]>
-
base-package 속성은 매퍼 인터페이스 파일이 있는 가장 상위 패키지를 지정하면 된다.
- 세미콜론이나 콤마를 구분자로 사용해서 한개 이상의 패키지를 셋팅할 수 있다.
+
base-package 속성은 매퍼 인터페이스 파일이 있는 가장 상위 패키지를 지정하면 된다.
+ 세미콜론이나 콤마를 구분자로 사용해서 한개 이상의 패키지를 셋팅할 수 있다.
매퍼는 지정된 패키지에서 재귀적으로 하위 패키지를 모두 검색할 것이다.
-
<mybatis:scan/>이 자동으로 주입할 수 있는 MapperFactoryBean를 생성하기 때문에
+
<mybatis:scan/>이 자동으로 주입할 수 있는 MapperFactoryBean를 생성하기 때문에
SqlSessionFactory 나 SqlSessionTemplate 를 명시할 필요가 없다.
하지만 한개 이상의 DataSource를 사용한다면 자동주입이 생각한데로 동작하지 않을수도 있다.
이 경우 사용할 빈 이름을 지정하기 위해 factory-ref 나 template-ref 속성을 사용할수 있다.
<mybatis:scan/>은 마커(marker) 인터페이스나 애노테이션을 명시해서 생성되는 매퍼를 필터링할수도 있다.
- annotation 프로퍼티는 검색할 애노테이션을 지정한다.
+ annotation 프로퍼티는 검색할 애노테이션을 지정한다.
marker-interface 프로퍼티는 검색할 상위 인터페이스를 지정한다.
이 두개의 프로퍼티를 모두 지정하면, 매퍼는 두 조건을 모두 만족하는 인터페이스만을 추가한다.
- 디폴트로 이 두가지 프로퍼티는 모두 null이다.
+ 디폴트로 이 두가지 프로퍼티는 모두 null이다.
그래서 base-package프로퍼티에 설정된 패키지 아래 모든 인터페이스가 매퍼로 로드될 것이다.
발견된 매퍼는 자동검색된 컴포넌트를 위한 스프링의 디폴트 명명규칙 전략(see the Spring reference document(Core Technologies -Naming autodetected components-))을 사용해서 빈이름이 명명된다.
빈 이름을 정하는 애노테이션이 없다면 매퍼의 이름에서 첫글자를 소문자로 변환한 형태로 빈 이름을 사용할 것이다.
- @Component 나 JSR-330의 @Named 애노테이션이 있다면 애노테이션에 정의한 이름을 그대로 사용할 것이다.
- annotation 프로퍼티를 org.springframework.stereotype.Component,
+ @Component 나 JSR-330의 @Named 애노테이션이 있다면 애노테이션에 정의한 이름을 그대로 사용할 것이다.
+ annotation 프로퍼티를 org.springframework.stereotype.Component,
javax.inject.Named(자바SE 1.6을 사용한다면) 또는 개발자가 스스로 작성한 애노테이션으로 셋팅할 수 있다.
그러면 애노테이션은 마커와 이름을 제공하는 역할로 동작할 것이다.
- 중요<context:component-scan/> 가 매퍼를 검색해서 등록을 하지 못할수도 있다.
+ 중요<context:component-scan/> 가 매퍼를 검색해서 등록을 하지 못할수도 있다.
매퍼는 인터페이스고 스프링에 빈으로 등록하기 위해서는 각각의 인터페이스를 찾기 위해 스캐너가 MapperFactoryBean 를 생성하는 방법을 알아야만 한다.
@MapperScan
-
-
@Configuration 라고 불리는 스프링의 자바설정을 사용한다면 <mybatis:scan/>보다는
+
+
@Configuration 라고 불리는 스프링의 자바설정을 사용한다면 <mybatis:scan/>보다는
@MapperScan를 사용하길 선호할것이다.
-
+
@MapperScan 애노테이션은 다음처럼 사용된다.
-
+
-
+
애노테이션은 앞서 본 <mybatis:scan/> 에서 설명하는 것과 동일하게 동작한다.
markerInterface 와 annotationClass 프로퍼티를 사용해서 마커 인터페이스와 애노테이션 클래스를 명시하게 한다.
- sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 사용해서
+ sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 사용해서
SqlSessionFactory 나 SqlSessionTemplate을 제공할 수도 있다.
@@ -197,19 +206,19 @@ public class AppConfig {
MapperScannerConfigurer
-
+
MapperScannerConfigurer는 평범한 빈처럼 XML애플리케이션 컨텍스트에 포함된 BeanDefinitionRegistryPostProcessor 이다.
MapperScannerConfigurer를 셋업하기 위해 다음의 스프링 설정을 추가하자.
]]>
-
sqlSessionFactory 나 sqlSessionTemplate를 지정할 필요가 있다면 빈참조가 아닌 빈이름이 필요하다.
+
sqlSessionFactory 나 sqlSessionTemplate를 지정할 필요가 있다면 빈참조가 아닌 빈이름이 필요하다.
value 프로퍼티는 빈 이름을 지정하고 ref 는 빈 참조를 지정하기 때문에 value 프로퍼티를 사용하자.
]]>
-
-
중요sqlSessionFactoryBean 과 sqlSessionTemplateBean 프로퍼티는
- 마이바티스 스프링 연동모듈 1.0.2 버전 이상에서만 사용이 가능하다. 하지만 MapperScannerConfigurer는 잦은 에러를 발생시키는
+
+
중요sqlSessionFactoryBean 과 sqlSessionTemplateBean 프로퍼티는
+ 마이바티스 스프링 연동모듈 1.0.2 버전 이상에서만 사용이 가능하다. 하지만 MapperScannerConfigurer는 잦은 에러를 발생시키는
PropertyPlaceholderConfigurer보다 앞서 실행되기 때문에 이 프로퍼티들은 사용하지 말길 바란다(deprecated).
대신 새롭게 추가된 프로퍼티인 sqlSessionFactoryBeanName 과 sqlSessionTemplateBeanName 를 사용하도록 권한다.
먼저 insertInteractionMetadata가 호출될것이고
update구문은 jdbc드라이버에 의해(keyProperty 와 keyColumn) 생성된 아이디들을 리턴하기 위해 설정되었다.
- InteractionMetadata 객체가 이 쿼리에 의해 업데이트되면 다음의 쿼리는
+ InteractionMetadata 객체가 이 쿼리에 의해 업데이트되면 다음의 쿼리는
insertInteraction를 통해 상위객체인 Interaction를 작성하기 위해 사용될수 있다.
-
방금 언급한 내용에 관련하여 JDBC드라이버가 똑같이 동작하지 않을수 있다.
- 이 글을 쓰는 시점에 H2 드라이버 1.3.168버전(org.h2.jdbc.JdbcStatement#getGeneratedKeys를 보라)만 배치모드에서 마지막 인덱스를 리턴한다.
+
방금 언급한 내용에 관련하여 JDBC드라이버가 똑같이 동작하지 않을수 있다.
+ 이 글을 쓰는 시점에 H2 드라이버 1.3.168버전(org.h2.jdbc.JdbcStatement#getGeneratedKeys를 보라)만 배치모드에서 마지막 인덱스를 리턴한다.
반면에 MySQL 드라이버는 기대한 것과 동일하게 동작하고 모든 아이디를 리턴한다.
-
\ No newline at end of file
+
diff --git a/src/site/ko/xdoc/boot.xml b/src/site/ko/xdoc/boot.xml
index 8e5ce5fa2e..8684637274 100644
--- a/src/site/ko/xdoc/boot.xml
+++ b/src/site/ko/xdoc/boot.xml
@@ -1,7 +1,7 @@
-
+
@@ -57,7 +57,7 @@
-->
-
+
diff --git a/src/test/java/org/mybatis/spring/submitted/autowire/spring.xml b/src/test/java/org/mybatis/spring/submitted/autowire/spring.xml
index 4d865af324..17b99f32b1 100644
--- a/src/test/java/org/mybatis/spring/submitted/autowire/spring.xml
+++ b/src/test/java/org/mybatis/spring/submitted/autowire/spring.xml
@@ -1,7 +1,7 @@
-
+
@@ -35,16 +35,16 @@
-
-
+
+
-
+
-
+
@@ -63,4 +63,4 @@
-
\ No newline at end of file
+
diff --git a/src/test/java/org/mybatis/spring/type/DummyMapperFactoryBean.java b/src/test/java/org/mybatis/spring/type/DummyMapperFactoryBean.java
index 2a1bf4aba5..65c844d1fe 100644
--- a/src/test/java/org/mybatis/spring/type/DummyMapperFactoryBean.java
+++ b/src/test/java/org/mybatis/spring/type/DummyMapperFactoryBean.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2010-2019 the original author or authors.
+ * Copyright 2010-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,14 @@
*/
package org.mybatis.spring.type;
+import java.lang.reflect.Proxy;
+import java.util.concurrent.atomic.AtomicInteger;
+
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.mybatis.spring.mapper.MapperFactoryBean;
-import java.lang.reflect.Proxy;
-import java.util.concurrent.atomic.AtomicInteger;
-
public class DummyMapperFactoryBean extends MapperFactoryBean {
public DummyMapperFactoryBean() {
From 526466cdd0bb34c63103d235618f3665156a594d Mon Sep 17 00:00:00 2001
From: "dependabot-preview[bot]"
<27856297+dependabot-preview[bot]@users.noreply.github.com>
Date: Tue, 23 Jun 2020 06:53:20 +0000
Subject: [PATCH 226/933] Bump jakarta.servlet-api from 4.0.3 to 4.0.4
Bumps [jakarta.servlet-api](https://github.com/eclipse-ee4j/servlet-api) from 4.0.3 to 4.0.4.
- [Release notes](https://github.com/eclipse-ee4j/servlet-api/releases)
- [Commits](https://github.com/eclipse-ee4j/servlet-api/commits)
Signed-off-by: dependabot-preview[bot]
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 324a223af5..808e16da8e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -301,7 +301,7 @@
jakarta.servletjakarta.servlet-api
- 4.0.3
+ 4.0.4test
From a3fa25f0364bd86853b49021cc77130d43f64885 Mon Sep 17 00:00:00 2001
From: nieqiuqiu
Date: Tue, 23 Jun 2020 17:18:51 +0800
Subject: [PATCH 227/933] Change the method name to getPropertyValue
---
.../spring/mapper/MapperScannerConfigurer.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java b/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java
index 578db89da0..63c52c2198 100644
--- a/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java
+++ b/src/main/java/org/mybatis/spring/mapper/MapperScannerConfigurer.java
@@ -402,11 +402,11 @@ private void processPropertyPlaceHolders() {
PropertyValues values = mapperScannerBean.getPropertyValues();
- this.basePackage = updatePropertyValue("basePackage", values);
- this.sqlSessionFactoryBeanName = updatePropertyValue("sqlSessionFactoryBeanName", values);
- this.sqlSessionTemplateBeanName = updatePropertyValue("sqlSessionTemplateBeanName", values);
- this.lazyInitialization = updatePropertyValue("lazyInitialization", values);
- this.defaultScope = updatePropertyValue("defaultScope", values);
+ this.basePackage = getPropertyValue("basePackage", values);
+ this.sqlSessionFactoryBeanName = getPropertyValue("sqlSessionFactoryBeanName", values);
+ this.sqlSessionTemplateBeanName = getPropertyValue("sqlSessionTemplateBeanName", values);
+ this.lazyInitialization = getPropertyValue("lazyInitialization", values);
+ this.defaultScope = getPropertyValue("defaultScope", values);
}
this.basePackage = Optional.ofNullable(this.basePackage).map(getEnvironment()::resolvePlaceholders).orElse(null);
this.sqlSessionFactoryBeanName = Optional.ofNullable(this.sqlSessionFactoryBeanName)
@@ -422,7 +422,7 @@ private Environment getEnvironment() {
return this.applicationContext.getEnvironment();
}
- private String updatePropertyValue(String propertyName, PropertyValues values) {
+ private String getPropertyValue(String propertyName, PropertyValues values) {
PropertyValue property = values.getPropertyValue(propertyName);
if (property == null) {
From 322a051d9050073c667bc76f61218637c3f91bf7 Mon Sep 17 00:00:00 2001
From: Kazuki Shimizu
Date: Thu, 25 Jun 2020 00:31:11 +0900
Subject: [PATCH 228/933] Change document source format to markdown from xdoc
---
pom.xml | 8 +
src/site/es/markdown/README.md | 18 ++
src/site/es/markdown/batch.md | 351 ++++++++++++++++++++
src/site/es/markdown/boot.md | 4 +
src/site/es/markdown/factorybean.md | 100 ++++++
src/site/es/markdown/getting-started.md | 99 ++++++
src/site/es/markdown/index.md | 55 ++++
src/site/es/markdown/mappers.md | 185 +++++++++++
src/site/es/markdown/sample.md | 63 ++++
src/site/es/markdown/sqlsession.md | 130 ++++++++
src/site/es/markdown/transactions.md | 141 ++++++++
src/site/es/markdown/using-api.md | 31 ++
src/site/es/xdoc/batch.xml | 409 ------------------------
src/site/es/xdoc/boot.xml | 36 ---
src/site/es/xdoc/factorybean.xml | 161 ----------
src/site/es/xdoc/getting-started.xml.vm | 158 ---------
src/site/es/xdoc/index.xml | 160 ---------
src/site/es/xdoc/mappers.xml | 272 ----------------
src/site/es/xdoc/sample.xml | 177 ----------
src/site/es/xdoc/sqlsession.xml | 168 ----------
src/site/es/xdoc/transactions.xml | 163 ----------
src/site/es/xdoc/using-api.xml | 90 ------
src/site/ja/markdown/README.md | 18 ++
src/site/ja/markdown/batch.md | 344 ++++++++++++++++++++
src/site/ja/markdown/boot.md | 4 +
src/site/ja/markdown/factorybean.md | 99 ++++++
src/site/ja/markdown/getting-started.md | 100 ++++++
src/site/ja/markdown/index.md | 52 +++
src/site/ja/markdown/mappers.md | 188 +++++++++++
src/site/ja/markdown/sample.md | 63 ++++
src/site/ja/markdown/sqlsession.md | 124 +++++++
src/site/ja/markdown/transactions.md | 137 ++++++++
src/site/ja/markdown/using-api.md | 32 ++
src/site/ja/xdoc/batch.xml | 374 ----------------------
src/site/ja/xdoc/boot.xml | 35 --
src/site/ja/xdoc/factorybean.xml | 152 ---------
src/site/ja/xdoc/getting-started.xml.vm | 140 --------
src/site/ja/xdoc/index.xml | 148 ---------
src/site/ja/xdoc/mappers.xml | 249 ---------------
src/site/ja/xdoc/sample.xml | 177 ----------
src/site/ja/xdoc/sqlsession.xml | 156 ---------
src/site/ja/xdoc/transactions.xml | 155 ---------
src/site/ja/xdoc/using-api.xml | 88 -----
src/site/ko/markdown/README.md | 18 ++
src/site/ko/markdown/batch.md | 353 ++++++++++++++++++++
src/site/ko/markdown/boot.md | 4 +
src/site/ko/markdown/factorybean.md | 97 ++++++
src/site/ko/markdown/getting-started.md | 98 ++++++
src/site/ko/markdown/index.md | 54 ++++
src/site/ko/markdown/mappers.md | 184 +++++++++++
src/site/ko/markdown/sample.md | 62 ++++
src/site/ko/markdown/sqlsession.md | 124 +++++++
src/site/ko/markdown/transactions.md | 134 ++++++++
src/site/ko/markdown/using-api.md | 30 ++
src/site/ko/xdoc/batch.xml | 373 ---------------------
src/site/ko/xdoc/boot.xml | 36 ---
src/site/ko/xdoc/factorybean.xml | 132 --------
src/site/ko/xdoc/getting-started.xml.vm | 118 -------
src/site/ko/xdoc/index.xml | 150 ---------
src/site/ko/xdoc/mappers.xml | 227 -------------
src/site/ko/xdoc/sample.xml | 168 ----------
src/site/ko/xdoc/sqlsession.xml | 129 --------
src/site/ko/xdoc/transactions.xml | 134 --------
src/site/ko/xdoc/using-api.xml | 74 -----
src/site/markdown/README.md | 18 ++
src/site/markdown/batch.md | 359 +++++++++++++++++++++
src/site/markdown/boot.md | 4 +
src/site/markdown/factorybean.md | 100 ++++++
src/site/markdown/getting-started.md | 100 ++++++
src/site/markdown/index.md | 54 ++++
src/site/markdown/mappers.md | 182 +++++++++++
src/site/markdown/sample.md | 64 ++++
src/site/markdown/sqlsession.md | 124 +++++++
src/site/markdown/transactions.md | 135 ++++++++
src/site/markdown/using-api.md | 30 ++
src/site/xdoc/batch.xml | 401 -----------------------
src/site/xdoc/boot.xml | 36 ---
src/site/xdoc/factorybean.xml | 224 -------------
src/site/xdoc/getting-started.xml.vm | 171 ----------
src/site/xdoc/index.xml | 169 ----------
src/site/xdoc/mappers.xml | 295 -----------------
src/site/xdoc/sample.xml | 177 ----------
src/site/xdoc/sqlsession.xml | 187 -----------
src/site/xdoc/transactions.xml | 181 -----------
src/site/xdoc/using-api.xml | 90 ------
src/site/zh/markdown/README.md | 18 ++
src/site/zh/markdown/batch.md | 343 ++++++++++++++++++++
src/site/zh/markdown/boot.md | 4 +
src/site/zh/markdown/factorybean.md | 94 ++++++
src/site/zh/markdown/getting-started.md | 97 ++++++
src/site/zh/markdown/index.md | 51 +++
src/site/zh/markdown/mappers.md | 183 +++++++++++
src/site/zh/markdown/sample.md | 62 ++++
src/site/zh/markdown/sqlsession.md | 122 +++++++
src/site/zh/markdown/transactions.md | 130 ++++++++
src/site/zh/markdown/using-api.md | 30 ++
src/site/zh/xdoc/batch.xml | 376 ----------------------
src/site/zh/xdoc/boot.xml | 36 ---
src/site/zh/xdoc/factorybean.xml | 140 --------
src/site/zh/xdoc/getting-started.xml.vm | 133 --------
src/site/zh/xdoc/index.xml | 142 --------
src/site/zh/xdoc/mappers.xml | 232 --------------
src/site/zh/xdoc/sample.xml | 164 ----------
src/site/zh/xdoc/sqlsession.xml | 143 ---------
src/site/zh/xdoc/transactions.xml | 142 --------
src/site/zh/xdoc/using-api.xml | 83 -----
106 files changed, 5808 insertions(+), 8531 deletions(-)
create mode 100644 src/site/es/markdown/README.md
create mode 100644 src/site/es/markdown/batch.md
create mode 100644 src/site/es/markdown/boot.md
create mode 100644 src/site/es/markdown/factorybean.md
create mode 100644 src/site/es/markdown/getting-started.md
create mode 100644 src/site/es/markdown/index.md
create mode 100644 src/site/es/markdown/mappers.md
create mode 100644 src/site/es/markdown/sample.md
create mode 100644 src/site/es/markdown/sqlsession.md
create mode 100644 src/site/es/markdown/transactions.md
create mode 100644 src/site/es/markdown/using-api.md
delete mode 100644 src/site/es/xdoc/batch.xml
delete mode 100644 src/site/es/xdoc/boot.xml
delete mode 100644 src/site/es/xdoc/factorybean.xml
delete mode 100644 src/site/es/xdoc/getting-started.xml.vm
delete mode 100644 src/site/es/xdoc/index.xml
delete mode 100644 src/site/es/xdoc/mappers.xml
delete mode 100644 src/site/es/xdoc/sample.xml
delete mode 100644 src/site/es/xdoc/sqlsession.xml
delete mode 100644 src/site/es/xdoc/transactions.xml
delete mode 100644 src/site/es/xdoc/using-api.xml
create mode 100644 src/site/ja/markdown/README.md
create mode 100644 src/site/ja/markdown/batch.md
create mode 100644 src/site/ja/markdown/boot.md
create mode 100644 src/site/ja/markdown/factorybean.md
create mode 100644 src/site/ja/markdown/getting-started.md
create mode 100644 src/site/ja/markdown/index.md
create mode 100644 src/site/ja/markdown/mappers.md
create mode 100644 src/site/ja/markdown/sample.md
create mode 100644 src/site/ja/markdown/sqlsession.md
create mode 100644 src/site/ja/markdown/transactions.md
create mode 100644 src/site/ja/markdown/using-api.md
delete mode 100644 src/site/ja/xdoc/batch.xml
delete mode 100644 src/site/ja/xdoc/boot.xml
delete mode 100644 src/site/ja/xdoc/factorybean.xml
delete mode 100644 src/site/ja/xdoc/getting-started.xml.vm
delete mode 100644 src/site/ja/xdoc/index.xml
delete mode 100644 src/site/ja/xdoc/mappers.xml
delete mode 100644 src/site/ja/xdoc/sample.xml
delete mode 100644 src/site/ja/xdoc/sqlsession.xml
delete mode 100644 src/site/ja/xdoc/transactions.xml
delete mode 100644 src/site/ja/xdoc/using-api.xml
create mode 100644 src/site/ko/markdown/README.md
create mode 100644 src/site/ko/markdown/batch.md
create mode 100644 src/site/ko/markdown/boot.md
create mode 100644 src/site/ko/markdown/factorybean.md
create mode 100644 src/site/ko/markdown/getting-started.md
create mode 100644 src/site/ko/markdown/index.md
create mode 100644 src/site/ko/markdown/mappers.md
create mode 100644 src/site/ko/markdown/sample.md
create mode 100644 src/site/ko/markdown/sqlsession.md
create mode 100644 src/site/ko/markdown/transactions.md
create mode 100644 src/site/ko/markdown/using-api.md
delete mode 100644 src/site/ko/xdoc/batch.xml
delete mode 100644 src/site/ko/xdoc/boot.xml
delete mode 100644 src/site/ko/xdoc/factorybean.xml
delete mode 100644 src/site/ko/xdoc/getting-started.xml.vm
delete mode 100644 src/site/ko/xdoc/index.xml
delete mode 100644 src/site/ko/xdoc/mappers.xml
delete mode 100644 src/site/ko/xdoc/sample.xml
delete mode 100644 src/site/ko/xdoc/sqlsession.xml
delete mode 100644 src/site/ko/xdoc/transactions.xml
delete mode 100644 src/site/ko/xdoc/using-api.xml
create mode 100644 src/site/markdown/README.md
create mode 100644 src/site/markdown/batch.md
create mode 100644 src/site/markdown/boot.md
create mode 100644 src/site/markdown/factorybean.md
create mode 100644 src/site/markdown/getting-started.md
create mode 100644 src/site/markdown/index.md
create mode 100644 src/site/markdown/mappers.md
create mode 100644 src/site/markdown/sample.md
create mode 100644 src/site/markdown/sqlsession.md
create mode 100644 src/site/markdown/transactions.md
create mode 100644 src/site/markdown/using-api.md
delete mode 100644 src/site/xdoc/batch.xml
delete mode 100644 src/site/xdoc/boot.xml
delete mode 100644 src/site/xdoc/factorybean.xml
delete mode 100644 src/site/xdoc/getting-started.xml.vm
delete mode 100644 src/site/xdoc/index.xml
delete mode 100644 src/site/xdoc/mappers.xml
delete mode 100644 src/site/xdoc/sample.xml
delete mode 100644 src/site/xdoc/sqlsession.xml
delete mode 100644 src/site/xdoc/transactions.xml
delete mode 100644 src/site/xdoc/using-api.xml
create mode 100644 src/site/zh/markdown/README.md
create mode 100644 src/site/zh/markdown/batch.md
create mode 100644 src/site/zh/markdown/boot.md
create mode 100644 src/site/zh/markdown/factorybean.md
create mode 100644 src/site/zh/markdown/getting-started.md
create mode 100644 src/site/zh/markdown/index.md
create mode 100644 src/site/zh/markdown/mappers.md
create mode 100644 src/site/zh/markdown/sample.md
create mode 100644 src/site/zh/markdown/sqlsession.md
create mode 100644 src/site/zh/markdown/transactions.md
create mode 100644 src/site/zh/markdown/using-api.md
delete mode 100644 src/site/zh/xdoc/batch.xml
delete mode 100644 src/site/zh/xdoc/boot.xml
delete mode 100644 src/site/zh/xdoc/factorybean.xml
delete mode 100644 src/site/zh/xdoc/getting-started.xml.vm
delete mode 100644 src/site/zh/xdoc/index.xml
delete mode 100644 src/site/zh/xdoc/mappers.xml
delete mode 100644 src/site/zh/xdoc/sample.xml
delete mode 100644 src/site/zh/xdoc/sqlsession.xml
delete mode 100644 src/site/zh/xdoc/transactions.xml
delete mode 100644 src/site/zh/xdoc/using-api.xml
diff --git a/pom.xml b/pom.xml
index 324a223af5..fa2f1b36f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -330,6 +330,8 @@
maven-site-pluginen,es,zh_CN,ja,ko
+
+ ${project.build.directory}/site-src
@@ -346,6 +348,12 @@
${project.basedir}/src/main/resources
+
+
+ ${project.basedir}/src/site
+ ${project.build.directory}/site-src
+ true
+
diff --git a/src/site/es/markdown/README.md b/src/site/es/markdown/README.md
new file mode 100644
index 0000000000..a3abaf2e40
--- /dev/null
+++ b/src/site/es/markdown/README.md
@@ -0,0 +1,18 @@
+# Tabla de contenido
+
+Esta página es para representar el índice en GitHub.
+
+> **NOTE:**
+>
+> Dado que el destino del enlace se especifica asumiendo que se convierte a html con maven-site-plugin, hay un ancla que se rompe en el renderizado en GitHub.
+
+* [Introducción](./index.md)
+* [Primeros pasos](./getting-started.md)
+* [SqlSessionFactoryBean](./factorybean.md)
+* [Transactions](./transactions.md)
+* [Uso de SqlSession](./sqlsession.md)
+* [Inyección de Mappers](./mappers.md)
+* [Spring Boot](./boot.md)
+* [Uso del API de MyBatis](./using-api.md)
+* [Spring Batch](./batch.md)
+* [Código de ejemplo](./sample.md)
diff --git a/src/site/es/markdown/batch.md b/src/site/es/markdown/batch.md
new file mode 100644
index 0000000000..1578477f98
--- /dev/null
+++ b/src/site/es/markdown/batch.md
@@ -0,0 +1,351 @@
+
+# Spring Batch
+
+Desde la versión 1.1.0 MyBatis-Spring proporciona dos beans para construir aplicaciones Spring Batch: `MyBatisPagingItemReader` y `MyBatisCursorItemReader` y `MyBatisBatchItemWriter`.
+Also, As of version 2.0.0 provides three builder classes for supporting the Java Configuration: the `MyBatisPagingItemReaderBuilder`, the `MyBatisCursorItemReaderBuilder` and the `MyBatisBatchItemWriterBuilder`.
+
+NOTA
+Esta sección se refiere a [Spring Batch](http://static.springsource.org/spring-batch/) y no a sesiones batch de MyBatis. Para obtener información sobre las sesiones batch ve a la sección [Usnado un SqlSession](sqlsession.html).
+
+## MyBatisPagingItemReader
+
+Este bean es un `ItemReader` que lee registros de una base de datos usando paginación.
+
+Ejecuta la sentencia especificada mediante la propiedad `setQueryId` para obtener los datos. La sentencia se ejecuta usando peticiones paginadas del tamaño indicando en la propiedad `setPageSize`.
+Al llamar al método `read()` éste devuelve el objeto que corresponde a la posición actual y solicita más páginas si es necesario.
+
+El reader recibe algunos parametros estándar y la SQL deberá hacer uso de algunos de ellos para construir un resultset del tamaño requerido. Los parametros son:
+
+* `_page`: el número de página a leer (comenzando en 0)
+* `_pagesize`: el tamaño de la página, es decir, el número de filas a devolver
+* `_skiprows`: el producto de `_page` por `_pagesize`
+
+Se pueden mapear en un statement de tipo select de la siguiente forma:
+
+```xml
+
+```
+
+A continuación se muestra un ejemplo de configuración:
+
+```xml
+
+
+
+
+```
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisPagingItemReader reader() {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+**Veamos un ejemplo más complejo:**
+
+```xml
+
+```
+```xml
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @StepScope
+ @Bean
+ public MyBatisPagingItemReader dateBasedCriteriaReader(
+ @Value("#{@datesParameters}") Map datesParameters) throws Exception {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(batchReadingSessionFactory())
+ .queryId("com.my.name.space.batch.ExampleMapper.queryUserInteractionsOnSpecificTimeSlot")
+ .parameterValues(datesParameters)
+ .pageSize(200)
+ .build();
+ }
+
+ @StepScope
+ @Bean
+ public Map datesParameters(
+ @Value("#{jobExecutionContext['EXTRACTION_START_DATE']}") LocalDate yesterday,
+ @Value("#{jobExecutionContext['TODAY_DATE']}") LocalDate today,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_MONTH_DATE']}") LocalDate firstDayOfTheMonth,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_PREVIOUS_MONTH_DATE']}") LocalDate firstDayOfThePreviousMonth) {
+ Map map = new HashMap<>();
+ map.put("yesterday", yesterday);
+ map.put("today", today);
+ map.put("first_day_of_the_month", firstDayOfTheMonth);
+ map.put("first_day_of_the_previous_month", firstDayOfThePreviousMonth);
+ return map;
+ }
+}
+```
+
+El ejemplo anterior hace uso de tres cosas distintas:
+
+* `sqlSessionFactory`: Puedes tu propio sessionFactory, podría ser útil si quires leer de varias bases de datos.
+* `queryId`: Si el código accede a varias tablas, y tienes distintas sentencias de consulta, puede ser interesante usar ficheros de mapeo distintos con namespaces distintos.
+ En este caso, al referirte a la query, no olvides incluir el namespace correspondiente.
+* `parameterValues`: Puedes pasar parametros adicionales en este mapa, el ejemplo de arriba usa un mapa que se construye usando una expresion SpEL y obteniendo valores del jobExecutionContext.
+ Las claves del mapa puede usarse en el fichero mapper de MyBatis (por ejemplo: *yesterday* se puede usar como `#{yesterday,jdbcType=TIMESTAMP}`).
+ Observa que el mapa y el reader se consutruyen en un solo `step` para que sea posible usar la expresión SpEL con el `jobExecutionContext`.
+ Adicionalmente si los type handlers de MyBatis están configurados correctamente puedes pasar instancias personalizadas como los parametros del ejemplo que son fechas JodaTime.
+* `pageSize`: Si le flujo batch está configurado con un tamaño de bloque (chunk size), es importante pasar esta información al reader, y eso se hace mediante esta propiedad.
+
+## MyBatisCursorItemReader
+
+Este bean es un `ItemReader` que lee registros de la base de datos usando un cursor.
+
+NOTA
+Para usar este bean necesitas al menos MyBatis 3.4.0 o superior.
+
+Ejecuta la sentencia especificada mediante la propiedad `setQueryId` para obtener los datos usando el método `selectCursor()`.
+Al llamar al método `read()` se devolverá el siguiente elemento del cursor hasta que no quede ninguno por devolver.
+
+El reader usa una conexión separada para que la sentencia no participe en ninguna transacción creada como parte del proceso del step.
+
+Cuando se usar un cursor puedes usar una sentencia convencional:
+
+```xml
+
+```
+
+A continuación se muestra un ejemplo de configuración:
+
+```xml
+
+
+
+
+```
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisCursorItemReader reader() {
+ return new MyBatisCursorItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+## MyBatisBatchItemWriter
+
+Es un `ItemWriter` que usa las capacidades de batch de `SqlSessionTemplate` para ejecutar sentencias batch para todos los elementos (items) proporcionados.
+El `SqlSessionFactory` debe configurarse con un executor de tipo `BATCH`.
+
+Ejecuta la sentencia indicada en la propiedad `statementId` cuando se invoca a `write()`. Se supone que `write()` se invoca dentro de una transacción.
+
+A continuación se muestra un ejemplo de configuración:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("com.my.name.space.batch.EmployeeMapper.updateEmployee")
+ .build();
+ }
+}
+```
+
+**Converting a item that read using ItemReader to an any parameter object:**
+
+By default behavior, the `MyBatisBatchItemWriter` passes a item that read using `ItemReader` (or convert by `ItemProcessor`) to the MyBatis(`SqlSession#update()`) as the parameter object.
+If you want to customize a parameter object that passes to the MyBatis, you can realize to use the `itemToParameterConverter` option. For example using `itemToParameterConverter` option, you can passes any objects other than the item object to the MyBatis.
+Follows below a sample:
+
+At first, you create a custom converter class (or factory method). The following sample uses a factory method.
+
+```java
+public class ItemToParameterMapConverters {
+ public static Converter> createItemToParameterMapConverter(String operationBy, LocalDateTime operationAt) {
+ return item -> {
+ Map parameter = new HashMap<>();
+ parameter.put("item", item);
+ parameter.put("operationBy", operationBy);
+ parameter.put("operationAt", operationAt);
+ return parameter;
+ };
+ }
+}
+```
+
+At next, you write a sql mapping.
+
+```xml
+
+```
+
+At last, you configure the `MyBatisBatchItemWriter`.
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() throws Exception {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("org.mybatis.spring.sample.mapper.PersonMapper.createPerson")
+ .itemToParameterConverter(createItemToParameterMapConverter("batch_java_config_user", LocalDateTime.now()))
+ .build();
+ }
+}
+```
+
+```xml
+
+
+
+
+
+
+
+
+
+
+```
+
+**Escribiendo en distintas tablas usando composite writers (con algunos condicionantes):**
+
+Esta técnica sólo puede usarse con MyBatis 3.2+, por que había un [error](http://code.google.com/p/mybatis/issues/detail?id=741) en las versiones anteriores que hacían que el writer funcionara de forma incorrecta.
+
+Si el batch necesita escribir datos complejos, como registros con asociaciones, o en distintas bases de datos, entonces es necesario sortear el problema de que los insert statements solo pueden escribir en una tabla.
+Para conseguir esto debes preparar un Item para que sea escrito por el writer. Sin embargo, dependiendo de las circunstancias puede ser interesante usar la siguiente técnica.
+El truco siguiente funciona con items con asociaciones simples o con tablas no relacionadas.
+
+Elabora el `item` de forma que *contenta* todos los resgistros distintos. Supon que para cada `item` hay una *Interaction* que tiene una asociación *InteractionMetadata* y dos filas no asociadas *VisitorInteraction* and *CustomerInteraction*.
+El objeto contenedor será de la siguiente forma:
+
+```java
+public class InteractionRecordToWriteInMultipleTables {
+ private final VisitorInteraction visitorInteraction;
+ private final CustomerInteraction customerInteraction;
+ private final Interaction interaction;
+ // ...
+}
+```
+```java
+public class Interaction {
+ private final InteractionMetadata interactionMetadata;
+}
+```
+
+Entonces en la configuración de spring habrá un `CompositeItemWriter` que usará writers delegados configurados especificamente para cada tipo de registro.
+Fijate que el *InteractionMetadata* es una asociacióin en el ejemplo por lo que debe ser escrita antes para que la Interaction pueda recibir la clave generada.
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public CompositeItemWriter> interactionsItemWriter() {
+ CompositeItemWriter compositeItemWriter = new CompositeItemWriter();
+ List> writers = new ArrayList<>(4);
+ writers.add(visitorInteractionsWriter());
+ writers.add(customerInteractionsWriter());
+ writers.add(interactionMetadataWriter());
+ writers.add(interactionWriter());
+ compositeItemWriter.setDelegates(writers);
+ return compositeItemWriter;
+ }
+}
+```
+
+Cada writer delegados se configura como sea necesario, por ejemplo para *Interaction* y *InteractionMetadata*:
+
+```xml
+
+```
+```xml
+
+```
+
+Al igual que con el reader el `statementId` puede hacer referencia al statement con un namespace como prefijo.
+
+Ahora es debe elaborarse el fichero de mapeo para cada tipo de registro, de la siguiente forma:
+
+```xml
+
+
+
+```
+```xml
+
+
+
+```
+
+Lo que sucede es que primeramente se llamará a `insertInteractionMetadata`, y la sentencia de update está configurada para devolver las claves autogeneradas (`keyProperty` y `keyColumn`).
+Una vez que el `InteractionMetadata` se ha almacenado por esta sentencia se puede ejecutar la siguiente para escribir el objeto padre `Interaction` mediante `insertInteraction`.
+
+***Sin embargo, ten en cuenta que los drivers JDBC se comportan distinto en este aspecto. A la fecha en la que se escribe esto
+el driver H2 1.3.168 solo devuelve el último ID incluso en modo BATCH (see `org.h2.jdbc.JdbcStatement#getGeneratedKeys`),
+mientras que el driver JDBC de MySQL se comporta como es de esperar y devuelve todos los IDs.***
diff --git a/src/site/es/markdown/boot.md b/src/site/es/markdown/boot.md
new file mode 100644
index 0000000000..cda8eb3a3d
--- /dev/null
+++ b/src/site/es/markdown/boot.md
@@ -0,0 +1,4 @@
+
+# Using Spring Boot
+
+Please see the [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) sub project docs for details.
diff --git a/src/site/es/markdown/factorybean.md b/src/site/es/markdown/factorybean.md
new file mode 100644
index 0000000000..598f28aef3
--- /dev/null
+++ b/src/site/es/markdown/factorybean.md
@@ -0,0 +1,100 @@
+
+# SqlSessionFactoryBean
+
+En MyBatis una `SqlSessionFactory` se crea mediante la clase `SqlSessionFactoryBuilder`. En MyBatis-Spring se usa la clase `SqlSessionFactoryBean` en su lugar.
+
+## Configuración
+
+Para crear un factory bean, pon lo siguiente en el fichero XML de configuración de Spring:
+
+```xml
+
+
+
+```
+
+La clase `SqlSessionFactoryBean` implementa el interfaz `FactoryBean` (see [the Spring documentation(Core Technologies -Customizing instantiation logic with a FactoryBean-](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-extension-factorybean)).
+Lo cual significa que el bean que crea Spring en última instancia **no** es un `SqlSessionFactoryBean` en si mismo, sino el objeto que la factoria devuelve como resultado de la llamada al método `getObject()`.
+En este caso, Spring creará un bean `SqlSessionFactory` durante el arranque de la aplicación y lo guardará bajo el nombre `sqlSessionFactory`. En Java, el código equivalente sería:
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+Normalmente no necesitarás utilizar directamente un `SqlSessionFactoryBean` o su correspondiente `SqlSessionFactory` directly.
+En su lugar, la factoría se utilizará para ser inyectada en `MapperFactoryBean`s o DAOs que extiendan de `SqlSessionDaoSupport`.
+
+## Properties
+
+La clase `SqlSessionFactory` solo tiene una propiedad obligatoria, un `DataSource`.
+Puede ser cualquier `DataSource` y se puede configurar como cualquier otra conexión a base de daots de Spring.
+
+Una propiedad muy común es la `configLocation` que se utiliza para indicar la localización del fichero de configuración XML de MyBatis.
+Normalmente solo es necesario dicho fichero si se requiere cambiar los valores por defecto de las secciones `` o ``.
+
+Es importante saber que este fichero de configuración **no** tiene por qué ser un fichero de configuración de MyBatis completo.
+Concretamente, los environments, dataSources y transactionManagers serán **ignorados**.
+`SqlSessionFactoryBean` crea su propio `Environment` de MyBatis con los valores configurados tal y como se requieren.
+
+Otro motivo para necesitar un fichero de configuración es que los ficheros de mapeo XML no estén en el mismo lugar del classpath que los mapper interfaces.
+En este caso hay dos opciones. La primera es especificar manualmente el classpath de los ficheros XML usando la sección `` del fichero de configuración de MyBatis.
+La segunda opción es usar la propiedad `mapperLocations` del factory bean.
+
+La propiedad `mapperLocations` recibe una lista de localizaciones de recursos. Se utiliza para indicar la ubicación de los ficheros de mapeo XML de MyBatis.
+El valor puede contener un patron tipo Ant para cargar todos los ficheros de un directorio o buscar de forma recursiva en todos los paths desde una localización base. Por ejemplo:
+
+```xml
+
+
+
+
+```
+
+Esto cargaría todos los ficheros de mapeo XML en el paquete sample.config.mappers y sus subpaquetes.
+
+Otra propiedad que puede ser necesaria en un entorno con transacciones gestionadas por contenedor es la `transactionFactoryClass`. Lee la sección de transacciones para obtener más detalles.
+
+En caso de usar la característica multi-db necesitarás informar la propiedad `databaseIdProvider` de la siguiente forma:
+
+```xml
+
+
+
+ sqlserver
+ db2
+ oracle
+ mysql
+
+
+
+```
+```xml
+
+
+
+
+
+```
+
+NOTE
+Since 1.3.0, `configuration` property has been added. It can be specified a `Configuration` instance directly without MyBatis XML configuration file.
+For example:
+
+```xml
+
+
+
+
+
+
+
+
+```
diff --git a/src/site/es/markdown/getting-started.md b/src/site/es/markdown/getting-started.md
new file mode 100644
index 0000000000..fdaedcaa30
--- /dev/null
+++ b/src/site/es/markdown/getting-started.md
@@ -0,0 +1,99 @@
+
+# Primeros pasos
+
+Este capítulo te mostrará en pocos pasos cómo instalar y configurar MyBatis-Spring y cómo construir
+una pequeña aplicación transaccional.
+
+## Instalación
+
+Para usar el módulo MyBatis-Spring, debes incluir el fichero `mybatis-spring-${project.version}.jar` y sus dependencias en el classpath.
+
+Si usas Maven simplemente añade la siguiente dependencia a tu pom.xml:
+
+```xml
+
+ org.mybatis
+ mybatis-spring
+ ${project.version}
+
+```
+
+## Configuración rápida
+
+Para usar MyBatis con Spring necesitas definir al menos dos cosas en tu contexto Spring: una `SqlSessionFactory` y al menos un mapper interface.
+
+En MyBatis-Spring se usa un `SqlSessionFactoryBean` para crear una `SqlSessionFactory`. Para configurar la factory bean pon lo siguiente en tu fichero de configuración de Spring:
+
+```xml
+
+
+
+```
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() throws Exception {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+Observa que la `SqlSessionFactory` requiere un `DataSource`. Éste puede ser cualquier `DataSource` y debe configurarse como cualquier otra conexión a base de datos de Spring.
+
+Asumamos que tienes un mapper interface definido de la siguiente forma:
+
+```java
+public interface UserMapper {
+ @Select("SELECT * FROM users WHERE id = #{userId}")
+ User getUser(@Param("userId") String userId);
+}
+```
+
+Este interface se añade a Spring usando un `MapperFactoryBean` de la siguiente forma:
+
+```xml
+
+
+
+
+```
+
+Observa que la clase del mapper indicada **debe** ser un interface, no una implementación. En este ejemplo se usan anotaciones para especificar la SQL, pero también es posible usar un fichero de mapeo XML.
+
+Una vez configurado, puedes inyectar mappers directamente en tus beans de servicio/negocio de la misma forma que inyectarías cualquier otro bean en Spring.
+La clase `MapperFactoryBean` se encargará de obtener una `SqlSession` y de cerrarla. Si hay una transación Spring en curso, la sesión se comitará o se hará rollback cuando la transacción finalice.
+Finalmente, cualquier excepción será traducida a una excepión `DataAccessException`s de Spring.
+
+If you use the Java Configuration:
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public UserMapper userMapper() throws Exception {
+ SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory());
+ return sqlSessionTemplate.getMapper(UserMapper.class);
+ }
+}
+```
+
+Invocar a MyBatis es sólo una línea de código:
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
diff --git a/src/site/es/markdown/index.md b/src/site/es/markdown/index.md
new file mode 100644
index 0000000000..ed37f9ad8c
--- /dev/null
+++ b/src/site/es/markdown/index.md
@@ -0,0 +1,55 @@
+
+# Introduction
+
+## ¿Qué es MyBatis-Spring?
+
+MyBatis-Spring permite integrar MyBatis con Spring. Esta librería permite que MyBatis participe en trasacciones Spring,
+se encarga de constuir mappers y `SqlSession`s e inyectarlos en otros beans, traduce excepciones de MyBatis en excepcines `DataAccessException`s de Spring y finalmente, permite construir aplicaciones libres de dependencias de MyBatis, Spring y MyBatis-Spring.
+
+## Motivación
+
+Spring version 2 sólo soporta iBATIS version 2. See hizo un intento de incluir el soporte de MyBatis 3 en Spring 3 (ver el [issue Jira](https://jira.springsource.org/browse/SPR-5991)).
+Pero desafortunadamente, el desarrollo de Spring 3 finalizó antes de que MyBatis 3 fuera liberado oficialmente.
+Dado que el equipo de Spring no quería liberar una versión basada en un producto no terminado el soporte de oficial tenía que esperar.
+Dado el interés de la comunidad en el soporte de MyBatis, la comunidad de MyBatis decidió que era el momento de unificar a los colaboradores interesados y proporcionar la integración con Spring como un sub-projecto de MyBatis en su lugar.
+
+## Requisitos
+
+Antes de comenzar con MyBatis-Spring, es muy importante que estés familiarizado con la terminología tanto de MyBatis como de Spring.
+Este documento no pretende proporcionar información de configuración básica de MyBatis o Spring.
+
+MyBatis-Spring requires following versions:
+
+| MyBatis-Spring | MyBatis | Spring Framework | Spring Batch | Java |
+| --- | --- | --- | --- | --- |
+| **2.0** | 3.5+ | 5.0+ | 4.0+ | Java 8+ |
+| **1.3** | 3.4+ | 3.2.2+ | 2.1+ | Java 6+ |
+
+## Agradecimientos
+
+Queremos agradecer a la todos los que han hecho de este proyecto una realidad (en orden alfabético):
+Eduardo Macarron, Hunter Presnall y Putthiphong Boonphong por la codificación, pruebas y documentación;
+a Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan y Tomas Pinos por sus contribuciones;
+y a Simone Tripodi por encontrarlos a todos y traerlos al proyecto MyBatis ;) Sin ellos este proyecto no existiría.
+
+## Colabora en mejorar esta documentación...
+
+Si ves que hay alguna carencia en esta documentación, o que falta alguna característica por documentar, te animamos a que lo investigues y la documentes tu mismo!
+
+Las fuentes de este manual están disponibles en formato xdoc en el [Git del proyecto](https://github.com/mybatis/mybatis-3/tree/master/src/site). Haz un fork, cambialas y envía un pull request.
+
+Eres el mejor candidato para documentar porque los lectores de esta documentación son gente como tú!
+
+## Translations
+
+Users can read about MyBatis-Spring in the following translations:
+
+
+
+Do you want to read about MyBatis in your own native language? Fill an issue providing patches with your mother tongue documentation!
diff --git a/src/site/es/markdown/mappers.md b/src/site/es/markdown/mappers.md
new file mode 100644
index 0000000000..51dd4293d8
--- /dev/null
+++ b/src/site/es/markdown/mappers.md
@@ -0,0 +1,185 @@
+
+# Inyectar mappers
+
+En lugar de codificar DAOs (data access objects) manualmente usando la clase `SqlSessionDaoSupport` o `SqlSessionTemplate`, Mybatis-Spring puede crear un mapper thread-safe que puedes inyectar directamente en otros beans.
+
+```xml
+
+
+
+```
+
+ Una vez inyectado, el mapper está listo para se usado en la lógica de aplicación:
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
+
+Observa que no se usa la `SqlSession` ni ninguna otra referencia a MyBatis en este código. No es necesario ni siquiera crear o cerrar la sesión, MyBatis-Spring se encarga de ello.
+
+
+## Registrar un mapper
+
+La forma de registrar un mapper varía según si quieres usar la configuración XML clásica o la nueva Java Config de Spring 3.0+ (También conocida como `@Configuration`).
+
+### Con confiugración XML
+
+Un mapper se registra en Spring incluyendo un `MapperFactoryBean` en tu fichero de configuración XML, de la siguiente forma:
+
+```xml
+
+
+
+
+```
+
+Si el mapper UserMapper tiene un fichero XML de mapeo asociado el `MapperFactoryBean` lo cargará automáticamente.
+Por lo tanto no es necesario especificar dicho mapper en el fichero de configuración de MyBatis a no ser que los ficheros XML estén en una lugar distinto del classpath.
+Ver la sección de `SqlSessionFactoryBean` y la propiedad [`configLocation`](factorybean.html) para más información.
+
+El `MapperFactoryBean` requiere o un `SqlSessionFactory` o un `SqlSessionTemplate`.
+Ambos se pueden informar usando sendas propiedades `sqlSessionFactory` y `sqlSessionTemplate`.
+Si ambas propiedades han sdo informadas la `SqlSessionFactory` se ignora.
+Dado que un `SqlSessionTemplate` debe tener un session factory dicho factory se usará por el `MapperFactoryBean`.
+
+### Con Java Config
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public MapperFactoryBean userMapper() throws Exception {
+ MapperFactoryBean factoryBean = new MapperFactoryBean<>(UserMapper.class);
+ factoryBean.setSqlSessionFactory(sqlSessionFactory());
+ return factoryBean;
+ }
+}
+```
+
+
+## Escanear mappers
+
+No es necesario registrar los mappers uno por uno en el fichero XML de Spring. En lugar de esto, puede dejar que MyBatis-Spring los busque en tu classpath.
+
+Hay tres formas distintas de hacerlo:
+
+* Usando el elemneto ``.
+* Usando la anotación `@MapperScan`
+* Usando un fichero clásico XML de configuración de Spring y añadiendo el bean `MapperScannerConfigurer`
+
+Tango `` como `@MapperScan` son características añadidas en MyBatis-Spring 1.2.0. `@MapperScan` requiere Spring 3.1+.
+
+Since 2.0.2, mapper scanning feature support a option (`lazy-initialization`) that control lazy initialization enabled/disabled of mapper bean.
+The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
+The default of this option is `false` (= not use lazy initialization).
+If developer want to use lazy initialization for mapper bean, it should be set to the `true` expressly.
+
+IMPORTANT
+If use the lazy initialization feature, the developer need to understand following limitations.
+If any of following conditions are matches, usually the lazy initialization feature cannot use on your application.
+
+* When refers to the statement of **other mapper** using ``(`@One`) and ``(`@Many`)
+* When includes to the fragment of **other mapper** using ``
+* When refers to the cache of **other mapper** using ``(`@CacheNamespaceRef`)
+* When refers to the result mapping of **other mapper** using `]]>
-
-
A continuación se muestra un ejemplo de configuración:
- El ejemplo anterior hace uso de tres cosas distintas:
-
-
-
-
sqlSessionFactory: Puedes tu propio sessionFactory, podría ser útil si quires leer de
- varias bases de datos.
-
queryId: Si el código accede a varias tablas, y tienes distintas sentencias de consulta,
- puede ser interesante usar ficheros de mapeo distintos con namespaces distintos.
- En este caso, al referirte a la query, no olvides incluir el namespace correspondiente.
-
parameterValues: Puedes pasar parametros adicionales en este mapa, el ejemplo de arriba
- usa un mapa que se construye usando una expresion SpEL y obteniendo valores del jobExecutionContext.
- Las claves del mapa puede usarse en el fichero mapper de MyBatis (por ejemplo:
- yesterday se puede usar como #{yesterday,jdbcType=TIMESTAMP}).
- Observa que el mapa y el reader se consutruyen en un solo step para que sea posible usar la expresión
- SpEL con el jobExecutionContext. Adicionalmente si los type handlers de MyBatis
- están configurados correctamente puedes pasar instancias personalizadas como los parametros del ejemplo que son
- fechas JodaTime.
-
pageSize: Si le flujo batch está configurado con un tamaño de bloque (chunk size),
- es importante pasar esta información al reader, y eso se hace mediante esta propiedad.
-
-
-
-
-
-
- Este bean es un ItemReader que lee registros de la base de datos usando un cursor.
-
-
-
- NOTA Para usar este bean necesitas al menos MyBatis 3.4.0 o superior.
-
-
-
- Ejecuta la sentencia especificada mediante la propiedad setQueryId para obtener los datos
- usando el método selectCursor().
- Al llamar al método read() se devolverá el siguiente elemento del cursor
- hasta que no quede ninguno por devolver.
-
-
-
- El reader usa una conexión separada para que la sentencia no participe en ninguna transacción creada como parte
- del proceso del step.
-
-
-
Cuando se usar un cursor puedes usar una sentencia convencional:
-
- SELECT id, name, job FROM employees ORDER BY id ASC
-]]>
-
-
A continuación se muestra un ejemplo de configuración:
- Es un ItemWriter que usa las capacidades de batch de SqlSessionTemplate para
- ejecutar sentencias batch para todos los elementos (items) proporcionados.
- El SqlSessionFactory debe configurarse con un executor de tipo BATCH.
-
-
-
- Ejecuta la sentencia indicada en la propiedad statementId cuando se invoca a write().
- Se supone que write() se invoca dentro de una transacción.
-
-
-
A continuación se muestra un ejemplo de configuración:
Converting a item that read using ItemReader to an any parameter object:
-
-
- By default behavior, the MyBatisBatchItemWriter passes a item that read using ItemReader
- (or convert by ItemProcessor) to the MyBatis(SqlSession#update()) as the parameter object.
- If you want to customize a parameter object that passes to the MyBatis, you can realize to use the itemToParameterConverter option.
- For example using itemToParameterConverter option, you can passes any objects other than the item object to the MyBatis.
- Follows below a sample:
-
-
-
- At first, you create a custom converter class (or factory method). The following sample uses a factory method.
-
Escribiendo en distintas tablas usando composite writers (con algunos condicionantes):
-
-
Esta técnica sólo puede usarse con MyBatis 3.2+, por que había un
- error
- en las versiones anteriores que hacían que el writer funcionara de forma incorrecta.
-
-
-
Si el batch necesita escribir datos complejos, como registros con asociaciones, o en distintas bases de datos,
- entonces es necesario sortear el problema de que los insert statements solo pueden escribir en una tabla.
- Para conseguir esto debes preparar un Item para que sea escrito por el writer. Sin embargo,
- dependiendo de las circunstancias puede ser interesante usar la siguiente técnica.
- El truco siguiente funciona con items con asociaciones simples o con tablas no relacionadas.
-
-
-
- Elabora el item de forma que contenta todos los resgistros distintos.
- Supon que para cada item hay una Interaction que tiene una asociación
- InteractionMetadata y dos filas no asociadas VisitorInteraction and
- CustomerInteraction. El objeto contenedor será de la siguiente forma:
-
-
-
-
-
- Entonces en la configuración de spring habrá un CompositeItemWriter que usará writers
- delegados configurados especificamente para cada tipo de registro. Fijate que el InteractionMetadata
- es una asociacióin en el ejemplo por lo que debe ser escrita antes para que la Interaction pueda recibir la clave
- generada.
-
Cada writer delegados se configura como sea necesario, por ejemplo para Interaction y
- InteractionMetadata:
-
-
-
-]]>
-
-
Al igual que con el reader el statementId puede hacer referencia al statement con un namespace como prefijo.
-
-
Ahora es debe elaborarse el fichero de mapeo para cada tipo de registro, de la siguiente forma:
-
-
-
-
-
-
-]]>
-
-
- Lo que sucede es que primeramente se llamará a insertInteractionMetadata, y la sentencia de update
- está configurada para devolver las claves autogeneradas (keyProperty y keyColumn).
- Una vez que el InteractionMetadata se ha almacenado por esta sentencia se puede ejecutar la siguiente para
- escribir el objeto padre Interaction mediante insertInteraction.
-
-
-
- Sin embargo, ten en cuenta que los drivers JDBC se comportan distinto en este aspecto. A la fecha en la que se escribe esto
- el driver H2 1.3.168 solo devuelve el último ID incluso en modo BATCH (see org.h2.jdbc.JdbcStatement#getGeneratedKeys),
- mientras que el driver JDBC de MySQL se comporta como es de esperar y devuelve todos los IDs.
-
- En MyBatis una SqlSessionFactory se crea mediante la clase
- SqlSessionFactoryBuilder. En MyBatis-Spring se usa la clase
- SqlSessionFactoryBean en su lugar.
-
-
-
-
- Para crear un factory bean, pon lo siguiente en el fichero XML de configuración de Spring:
-
-
-
-]]>
-
- La clase SqlSessionFactoryBean implementa el interfaz FactoryBean
- (see the Spring documentation(Core Technologies -Customizing instantiation logic with a FactoryBean-)).
- Lo cual significa que el bean que crea Spring
- en última instancia no es un SqlSessionFactoryBean en si mismo, sino el
- objeto que la factoria devuelve como resultado de la llamada al método
- getObject(). En este caso, Spring creará un bean
- SqlSessionFactory durante el arranque de la aplicación y lo guardará bajo el nombre
- sqlSessionFactory. En Java, el código equivalente sería:
-
-
-
-
-
- Normalmente no necesitarás utilizar directamente un SqlSessionFactoryBean
- o su correspondiente SqlSessionFactory directly.
- En su lugar, la factoría se utilizará para ser inyectada en MapperFactoryBeans o
- DAOs que extiendan de SqlSessionDaoSupport.
-
-
-
-
-
-
- La clase SqlSessionFactory solo tiene una propiedad obligatoria, un DataSource.
- Puede ser cualquier DataSource y se puede configurar como cualquier otra conexión a base de daots de Spring.
-
-
-
- Una propiedad muy común es la configLocation que se utiliza para indicar la localización del fichero de configuración
- XML de MyBatis. Normalmente solo es necesario dicho fichero si se requiere cambiar los valores por defecto de las secciones
- <settings> o <typeAliases>.
-
-
-
- Es importante saber que este fichero de configuración no tiene por qué ser un fichero de configuración de MyBatis completo.
- Concretamente, los environments, dataSources y transactionManagers serán ignorados.
- SqlSessionFactoryBean crea su propio Environment de MyBatis con los valores configurados tal y como se requieren.
-
-
-
- Otro motivo para necesitar un fichero de configuración es que los ficheros de mapeo XML no estén en el mismo lugar del classpath
- que los mapper interfaces. En este caso hay dos opciones. La primera es especificar manualmente el classpath de los ficheros XML
- usando la sección <mappers> del fichero de configuración de MyBatis. La segunda opción es usar la propiedad
- mapperLocations del factory bean.
-
-
-
- La propiedad mapperLocations recibe una lista de localizaciones de recursos. Se utiliza para indicar la ubicación de los
- ficheros de mapeo XML de MyBatis. El valor puede contener un patron tipo Ant para cargar todos los ficheros de un directorio o
- buscar de forma recursiva en todos los paths desde una localización base. Por ejemplo:
-
-
-
-
-
-]]>
-
-
- Esto cargaría todos los ficheros de mapeo XML en el paquete sample.config.mappers y sus subpaquetes.
-
-
-
- Otra propiedad que puede ser necesaria en un entorno con transacciones gestionadas por contenedor es la
- transactionFactoryClass. Lee la sección de transacciones para obtener más detalles.
-
-
-
- En caso de usar la característica multi-db necesitarás informar la propiedad databaseIdProvider
- de la siguiente forma:
-
- NOTE
- Since 1.3.0, configuration property has been added.
- It can be specified a Configuration instance directly without MyBatis XML configuration file.
- For example:
-
- Para usar MyBatis con Spring necesitas definir al menos dos cosas en tu contexto Spring: una
- SqlSessionFactory y al menos un mapper interface.
-
-
-
- En MyBatis-Spring se usa un
- SqlSessionFactoryBean
- para crear una
- SqlSessionFactory
- . Para configurar la factory bean pon lo siguiente en tu
- fichero de configuración de Spring:
-
-
-
-
-]]>
-
-
-
-
- Observa que la SqlSessionFactory
- requiere un
- DataSource
- . Éste puede ser cualquier
- DataSource
- y debe configurarse como cualquier otra conexión a base de datos
- de Spring.
-
-
-
- Asumamos que tienes un mapper interface definido de la siguiente forma:
-
-
-
-
- Este interface se añade a Spring usando un
- MapperFactoryBean
- de la siguiente forma:
-
-
-
-
-]]>
-
-
- Observa que la clase del mapper indicada
- debe
- ser un interface, no una implementación. En este ejemplo se usan
- anotaciones para especificar la SQL, pero también es posible
- usar un fichero de mapeo XML.
-
-
-
- Una vez configurado, puedes inyectar mappers directamente en tus
- beans de servicio/negocio de la misma forma que inyectarías cualquier
- otro bean en Spring.
- La clase MapperFactoryBean se encargará de obtener
- una SqlSession y de cerrarla. Si hay una transación Spring
- en curso, la sesión se comitará o se hará rollback cuando la transacción
- finalice. Finalmente, cualquier excepción será traducida a una excepión
- DataAccessExceptions de Spring.
-
-
-
- If you use the Java Configuration:
-
-
-
-
-
- Invocar a MyBatis es sólo una línea de código:
-
- MyBatis-Spring permite integrar MyBatis con Spring.
- Esta librería permite que MyBatis participe en trasacciones Spring, se encarga de constuir
- mappers y SqlSessions e inyectarlos en otros beans, traduce excepciones
- de MyBatis en excepcines DataAccessExceptions de Spring y finalmente,
- permite construir aplicaciones libres de dependencias de MyBatis, Spring y MyBatis-Spring.
-
-
-
-
-
- Spring version 2 sólo soporta iBATIS version 2. See hizo un intento de incluir el soporte
- de MyBatis 3 en Spring 3 (ver el issue Jira).
- Pero desafortunadamente, el desarrollo de Spring 3 finalizó antes de que MyBatis 3 fuera liberado oficialmente.
- Dado que el equipo de Spring no quería liberar una versión basada en un producto no terminado el soporte de
- oficial tenía que esperar. Dado el interés de la comunidad en el soporte de MyBatis,
- la comunidad de MyBatis decidió que era el momento de unificar a los colaboradores interesados
- y proporcionar la integración con Spring como un sub-projecto de MyBatis en su lugar.
-
-
-
-
-
- Antes de comenzar con MyBatis-Spring, es muy importante que estés familiarizado con la terminología tanto de
- MyBatis como de Spring. Este documento no pretende proporcionar información de configuración básica de
- MyBatis o Spring.
-
-
- MyBatis-Spring requires following versions:
-
-
-
-
-
- MyBatis-Spring
-
-
- MyBatis
-
-
- Spring Framework
-
-
- Spring Batch
-
-
- Java
-
-
-
-
-
-
- 2.0
-
-
- 3.5+
-
-
- 5.0+
-
-
- 4.0+
-
-
- Java 8+
-
-
-
-
- 1.3
-
-
- 3.4+
-
-
- 3.2.2+
-
-
- 2.1+
-
-
- Java 6+
-
-
-
-
-
-
-
-
- Queremos agradecer a la todos los que han hecho de este proyecto una realidad (en orden alfabético):
- Eduardo Macarron, Hunter Presnall y Putthiphong Boonphong por la codificación, pruebas y documentación;
- a Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan y Tomas Pinos
- por sus contribuciones; y a Simone Tripodi por encontrarlos a todos y traerlos al proyecto MyBatis ;)
- Sin ellos este proyecto no existiría.
-
-
-
-
-
- Si ves que hay alguna carencia en esta documentación, o que falta alguna característica por documentar,
- te animamos a que lo investigues y la documentes tu mismo!
-
-
- Las fuentes de este manual están disponibles en formato xdoc en el
- Git del proyecto.
- Haz un fork, cambialas y envía un pull request.
-
-
- Eres el mejor candidato para documentar porque los lectores de esta documentación son gente como tú!
-
-
-
-
Users can read about MyBatis-Spring in the following translations:
- En lugar de codificar DAOs (data access objects) manualmente usando la clase
- SqlSessionDaoSupport o SqlSessionTemplate, Mybatis-Spring
- puede crear un mapper thread-safe que puedes inyectar directamente en otros beans.
-
-
-
-
-]]>
-
-
- Una vez inyectado, el mapper está listo para se usado en la lógica de aplicación:
-
-
-
- Observa que no se usa la SqlSession ni ninguna otra referencia a MyBatis en este código.
- No es necesario ni siquiera crear o cerrar la sesión, MyBatis-Spring se encarga de ello.
-
-
-
-
-
- La forma de registrar un mapper varía según si quieres usar la configuración XML clásica o la nueva Java Config de Spring 3.0+
- (También conocida como @Configuration).
-
-
Con confiugración XML
-
-
- Un mapper se registra en Spring incluyendo un MapperFactoryBean en tu fichero de configuración XML, de la siguiente forma:
-
-
-
-
-]]>
-
-
- Si el mapper UserMapper tiene un fichero XML de mapeo asociado el MapperFactoryBean
- lo cargará automáticamente. Por lo tanto no es necesario especificar dicho mapper en el fichero
- de configuración de MyBatis a no ser que los ficheros XML estén en una lugar distinto del classpath.
- Ver la sección de SqlSessionFactoryBean y la propiedad
- configLocation
- para más información.
-
-
-
- El MapperFactoryBean requiere o un
- SqlSessionFactory o un SqlSessionTemplate.
- Ambos se pueden informar usando sendas propiedades sqlSessionFactory y
- sqlSessionTemplate.
- Si ambas propiedades han sdo informadas la SqlSessionFactory se ignora.
- Dado que un SqlSessionTemplate debe tener un session factory
- dicho factory se usará por el MapperFactoryBean.
-
- No es necesario registrar los mappers uno por uno en el fichero XML de Spring.
- En lugar de esto, puede dejar que MyBatis-Spring los busque en tu classpath.
-
-
-
- Hay tres formas distintas de hacerlo:
-
-
-
Usando el elemneto <mybatis:scan/>.
-
Usando la anotación @MapperScan
-
Usando un fichero clásico XML de configuración de Spring y añadiendo el bean MapperScannerConfigurer
-
-
-
Tango <mybatis:scan/> como @MapperScan son características añadidas en MyBatis-Spring 1.2.0.
- @MapperScan requiere Spring 3.1+.
-
-
- Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
- that control lazy initialization enabled/disabled of mapper bean.
- The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
- The default of this option is false (= not use lazy initialization).
- If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
-
-
- IMPORTANT If use the lazy initialization feature,
- the developer need to understand following limitations. If any of following conditions are matches,
- usually the lazy initialization feature cannot use on your application.
-
-
-
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
-
When includes to the fragment of other mapper using ]]>
-
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
-
When refers to the result mapping of other mapper using ]]>(@ResultMap)
-
-
-
- NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
-
-
-
-
-
- Since 2.0.6, the develop become can specified scope of mapper using mapper scanning feature option(default-scope)
- and scope annotation(@Scope, @RefreshScope, etc ...).
- The motivation for adding this option is supporting the refresh scope provided by the Spring Cloud.
- The default of this option is empty (= equiv to specify the singleton scope).
- The default-scope apply to the mapper bean(MapperFactoryBean) when scope of scanned bean definition
- is singleton(default scope) and create a scoped proxy bean for scanned mapper when final scope is not singleton.
-
-
-
<mybatis:scan/>
-
-
- El elemento XML <mybatis:scan/> busca mappers de una forma muy similar a cómo
- <context:component-scan/> busca beans.
-
-
-
A continuación se muestra un fichero XML de configuración:
-
-
-
-
-
-
-
-]]>
-
-
- La propiedad basePackage te permite indicar el paquete base donde residen tus mappers.
- Puedes indicar más de un paquete usando un punto y coma o una coma como separador. Los mappers serán buscados
- de forma recursiva comenzando en el/los paquetes especificados.
-
-
-
- Fíjate que no es necesario indicar una SqlSessionFactory o
- SqlSessionTemplate porque el <mybatis:scan/>
- creará MapperFactoryBeans que pueden ser autowired. Pero si usas más de un DataSource
- el autowire puede que no te funcione. En este caso puedes usar las propiedades factory-ref or
- template-ref para indicar los beans correctos a utilizar.
-
-
-
- <mybatis:scan/> soporta el filtrado de mappers mediante una interfaz marcador o una anotación.
- La propiedad annotation especifica la anotación que se debe buscar.
- La propiedad marker-interface especifica la interfaz a buscar.
- Si se indican ambas se añadirán todos los mappers que cumplan cualquier criterio.
- Por defecto ambas propiedades son null asi que todos los interfaces de los paquetes base serán cargados como mappers.
-
-
-
- Los mappers descubiertos serán nombrados usando la estratégia de nombres por defecto de Spring para los componentes
- autodetectados (see the Spring reference document(Core Technologies -Naming autodetected components-)).
- Es decir, si no se encuentra ninguna anotación, se usará el nombre no cualificado sin capitalizar del mapper.
- Pero si se encuentra una anotación @Component o JSR-330 @Named se obtendrá el nombre de dicha anotación.
- Fíjate que puedes usar como valor de la annotation el valor org.springframework.stereotype.Component,
- javax.inject.Named (if you have JSE 6) o una anotación propia
- (que debe ser a su vez anotada) de forma que la anotación hará las veces de localizador y de proveedor de nombre.
-
-
-
- NOTE<context:component-scan/>
- no puede encontrar y registrar mappers. Los mappers son interfaces y, para poderlos registrar en Spring,
- el scanner deben conocer cómo crear un MapperFactoryBean para cada interfaz encontrado.
-
-
-
@MapperScan
-
-
- Si usas la Java Configuration de Spring (@Configuration) posiblemente prefieras usar
- @MapperScan en lugar de <mybatis:scan/>.
-
-
-
La anotación @MapperScan se usa de la siguiente forma:
-
-
-
-
- La anotación fucniona exactamente igual que <mybatis:scan/> que hemos visto en la sección anterior.
- También te permite especificar un interfaz marcador o una anotación mediante sus propiedades
- markerInterface y annotationClass.
- Tambien puedes indicar una SqlSessionFactory o un SqlSessionTemplate específicos
- mediante las propiedades sqlSessionFactory y sqlSessionTemplate.
-
-
-
- NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
-
-
-
MapperScannerConfigurer
-
-
- MapperScannerConfigurer es un BeanDefinitionRegistryPostProcessor
- que se puede incluir como un bean normal en el fichero clásico XML de configuración de Spring.
- Para configurar un MapperScannerConfigurer añade lo siguiente al fichero de configuración de Spring:
-
-
-
-]]>
-
-
- Si quieres indicar un sqlSessionFactory o un sqlSessionTemplate
- observa que se requeiren los nombres de los beans y no sus referencias
- por ello se usa el atributo value en lugar del habitual ref:
-
- NOTE
- See JPetstore 6 demo to know about how to use Spring with a full web application server.
-
-
-
- You can check out sample code from the MyBatis-Spring repo:
-
-
- Any of the samples can be run with JUnit 5.
-
-
- The sample code shows a typical design where a transactional service gets domain objects from a data access layer.
-
-
- FooService.java acts as the service:
-
-
-
- It is a transactional bean, so when the method is called, the transaction is started
- and the transaction is committed when the method ends without throwing an uncaught exception.
- Notice that transactional behaviour is configured with the
- @Transactional
- attribute. This is not required; any other way provided by Spring can be used to demarcate
- your transactions.
-
-
- This service calls a data access layer built with MyBatis. This layer
- consists on a just an interface UserMapper.java
- that will be used with a dynamic proxy built by MyBatis at
- runtime and injected into the service by Spring.
-
-
-
- Note that, for the sake of simplicity we used the interface UserMapper.java for the DAO scenario
- where a DAO is built with an interface and a implementation though in this case it would have been more
- adequate to use an interface called UserDao.java instead.
-
-
- We will see different ways to find the mapper interface, register it to Spring and inject it into the service bean:
-
-
-
Scenarios
-
-
-
Sample test
-
Description
-
-
-
-
-
- SampleMapperTest.java
-
-
- Shows you the base configuration based on a MapperFactoryBean
- that will dynamically build an implementation for UserMapper
-
-
-
-
- SampleScannerTest.java
-
-
- Shows how to use the MapperScannerConfigurer so all the mappers in a project are autodiscovered.
-
-
-
-
- SampleSqlSessionTest.java
-
-
- Shows how to hand code a DAO using a Spring managed SqlSession
- and providing your own implementation UserDaoImpl.java.
-
-
-
-
- SampleEnableTest
-
-
- Shows how to use Spring's @Configuration with the @MapperScann annotation so
- mappers are autodiscovered.
-
-
-
-
- SampleNamespaceTest
-
-
- Shows how to use the custom MyBatis XML namespace.
-
-
-
-
- SampleJavaConfigTest.java
-
-
- Shows how to use Spring's @Configuration to create MyBatis beans manually.
-
-
-
-
- SampleJobJavaConfigTest.java
-
-
- Shows how to use ItemReader and ItemWriter on Spring Batch using Java Configuration.
-
-
-
-
- SampleJobXmlConfigTest.java
-
-
- Shows how to use ItemReader and ItemWriter on Spring Batch using XML Configuration.
-
-
-
-
-
- Please take a look at the different applicationContext.xml files to see MyBatis-Spring in action.
-
- En MyBatis usas un SqlSessionFactory para crear un SqlSession.
- Una vez tienes una sesión, la usas para ejecutar tus mapped statements, hacer commit o rollback y finalmente
- cuando no la necesitas la cierras. Con MyBatis-Spring no es necesario que utilices la SqlSessionFactory
- directamente porque puedes inyectar en tus beans una SqlSession thread safe (reentrante)
- que hará de forma automática el commit, rollback y se cerrará conforme a la configuración de la transacción en Spring.
-
-
-
-
- El SqlSessionTemplate is el corazón de MyBatis-Spring.
- Implementa SqlSession y está pensado para que sea directamente reemplazable por cualquier código
- que actualmente use SqlSession.
- SqlSessionTemplate es thread safe y se puede compartir por más de un DAO.
-
-
-
- Cuando se invoca a cualquier método SQL, incluyendo cualquier método de un mapper devuelto por
- getMapper(), el SqlSessionTemplate
- se asegurará de que la SqlSession utilizada es la asociada con la transacción Spring en curso.
- Adicionalmente, se encarga de gestionar su ciclo de vida, incluyendo su cierre, commit o rollback de la sesión si fuera necesario.
-
-
-
- Se debe usar siempre un SqlSessionTemplate en lugar de la implementación de sesión
- por default MyBatis: DefaultSqlSession
- porque el template puede participar en transacciones Spring y es thread safe con lo que puede ser inyectado
- en múltiples mappers (proxies). Cambiar de uno a otro puede crear problemas de integridad de datos.
-
-
-
- El SqlSessionTemplate puede construirse usando un SqlSessionFactory como argumento de su constructor.
-
-
-
-]]>
-
-
-
-
- Este bean puede ser inyectado directamente en tus DAOs. Necesitarás una propiedad
- SqlSession en tu bean como se muestra a continuación:
-
-
-
- E inyectar el SqlSessionTemplate de la siguiente forma:
-
-
-
-]]>
-
-
- El SqlSessionTemplate tiene también un constructor que recibe como parámetro
- un ExecutorType. Esto permite construir, por ejemplo,
- una SqlSession batch utilizando la siguiente configuracíon de Spring:
-
-
-
-
-]]>
-
-
-
-
- Ahora todos tus statements se ejecutarán en batch de forma que puedes programar lo siguiente:
-
- users) {
- for (User user : users) {
- sqlSession.insert("org.mybatis.spring.sample.mapper.UserMapper.insertUser", user);
- }
-}]]>
-
-
- Fijate que esta configuración si el método de ejecución deseado es distinto del establecido por defecto
- en el SqlSessionFactory.
-
-
-
- La contrapartida de esto es que no es posible cambiar el méodo de ejecución dentro de una transacción.
- Por tanto asegurate que o bien todas las llamadas a un SqlSessionTemplates con distinto método de ejecución
- se ejecutan en una transacción diferente (p.ej: with PROPAGATION_REQUIRES_NEW) o completamente fuera de la transacción.
-
-
-
-
-
- SqlSessionDaoSupport es una clase de soporte abstracta que proporciona un SqlSession.
- Llamando a getSqlSession() obtiene un SqlSessionTemplate
- que puedes utilizar para ejecutar métodos SQL, como sigue:
-
-
-
- Normalmente es preferible usar un MapperFactoryBean a esta clase dao que no requeire código extra.
- Pero esta clase es de utilidad cuando es necesario hacer algún otro tipo de trabajo no-MyBatis en el DAO y se necesitan
- clases concretas.
-
-
-
- SqlSessionDaoSupport que se informe la propiedad
- sqlSessionFactory o la sqlSessionTemplate.
- Si se informan ambas propiedades, la sqlSessionFactory se ignora.
-
-
-
- Asumiendo una clase UserDaoImpl que extiende
- SqlSessionDaoSupport, se puede configurar Spring de la siguiente forma:
-
- Uno de los principales motivos para usar MyBatis-Spring es que permite que MyBatis participe en transacciones
- de Spring. En lugar de haber creado un TransactionManager especifico para MyBatis, MyBatis-Spring aprovecha
- el existente DataSourceTransactionManager de Spring.
-
-
- Una vez que has configurado un TransactionManager in Spring puedes configurar tus transacciones en Spring como siempre.
- Tanto las anotaciones @Transactional como las configuraciones de tipo AOP se soportan.
- Se creará una sola instancia de SqlSession para toda la transacción.
- Se hará commit o rollback de esta sesión cuando la transacción finalice.
-
-
- MyBatis-Spring se encargará de gestionar las transacciones de forma transparente una vez se hayan configurado. No es necesario
- incluir código adicional en tus clases.
-
-
-
-
- Para habilitar las transacciones Spring, simplemente crea un DataSourceTransactionManager en tu fichero de configuración:
-
-
-
-]]>
-
-
-
-
- El DataSource especificado puede ser cualquier DataSource JDBC que usarías normalmente con Spring.
- Esto incluye connection pools y DataSources obtenidos mediante JNDI.
-
-
- Fijate que el DataSource especificado en el transaction manager debe ser el mismo que el que se use para
- crear el SqlSessionFactoryBean o la gestión de transacciones no funcionará.
-
-
-
-
-
- Si estás usando un contenedor JEE y quiere que spring participe en las transacciones gestionadas por contenedor (CMT), entonces debes
- configurar un JtaTransactionManager en Spring o alguna de sus clases específicas de cada contenedor.
- Lo más sencillo es utilizar el namespace tx de Spring or the JtaTransactionManagerFactoryBean:
-
- ]]>
-
-
-
-
- Con esta configuración, MyBatis se comportará como cualquier otro recurso configurado con CMT.
- Spring utilizará cualquier transacción CMT existente y asociará la SqlSession a ella.
- Si no no hay ninguna transacción previa pero se necesita una en base a la configuración de la transacción, Spring creará
- una transacción gestionada por contenedor nueva.
-
-
- Fijate que si quieres usar transacciones CMT pero no quieres utilizar la gestión de transacciones de Spring
- no debes configurar ningun transaction manager en Spring y debes
- configurar el SqlSessionFactoryBean para que use la clase ManagedTransactionFactory de MyBatis de la siguiente forma:
-
-
-
-
-
-
-]]>
-
-
-
-
-
-
-
- La interfaz SqlSession proporciona métodos especificos para gestionar la transacción.
- Pero al usar MyBatis-Spring en tus beans se inyectará una SqlSession o un mapper gestionados por Spring.
- Esto significa que Spring siempre gestionará tus transacciones.
-
-
- No puedes llamar a los métodos SqlSession.commit(), SqlSession.rollback()
- o SqlSession.close() en una SqlSession gestionada por Spring.
- Si lo intentas obtendrás una excepción UnsupportedOperationException.
- Además, estos métodos no se exponen en los mapper interfaces.
-
-
- Independientemente de el estado del autocommit de la conexión JDBC cualquier llamada
- a un metodo SQL de SqlSession fuera de una transacción Spring será automaticamente commitada.
-
- With MyBatis-Spring, you can continue to directly use the MyBatis API.
- Simply create an SqlSessionFactory in Spring using
- SqlSessionFactoryBean and use the factory in your code.
-
-
-
-
- Use this option with care because wrong usage may produce runtime errors or
- worse, data integrity problems. Be aware of the following caveats with direct API usage:
-
-
-
-
- It will not participate in any Spring transactions.
-
-
-
-
- If the SqlSession is using a DataSource
- that is also being used by a Spring transaction manager and there is currently
- a transaction in progress, this code will throw an exception.
-
-
-
-
- MyBatis' DefaultSqlSession is not thread safe. If you
- inject it in your beans you will get errors.
-
-
-
-
- Mappers created using DefaultSqlSession are not thread safe either.
- If you inject them it in your beans you will get errors.
-
-
-
-
- You must make sure that your SqlSessions
- are always closed in a finally block.
-
-
-
-
-
-
diff --git a/src/site/ja/markdown/README.md b/src/site/ja/markdown/README.md
new file mode 100644
index 0000000000..3280241e0c
--- /dev/null
+++ b/src/site/ja/markdown/README.md
@@ -0,0 +1,18 @@
+# 目次
+
+このページはGitHub上でドキュメントの目次を表示するため用意したものです。
+
+> **NOTE:**
+>
+> リンクはmaven-site-pluginでHTMLに変換することを前提に指定されているため、GitHubでのレンダリングではリンク切れになっているものがあります。
+
+* [イントロダクション](./index.md)
+* [スタートガイド](./getting-started.md)
+* [SqlSessionFactoryBean](./factorybean.md)
+* [トランザクション](./transactions.md)
+* [SqlSessionの利用](./sqlsession.md)
+* [Mapperの注入](./mappers.md)
+* [Spring Boot](./boot.md)
+* [MyBatis APIの利用](./using-api.md)
+* [Spring Batch](./batch.md)
+* [サンプルコード](./sample.md)
diff --git a/src/site/ja/markdown/batch.md b/src/site/ja/markdown/batch.md
new file mode 100644
index 0000000000..0c0d55257e
--- /dev/null
+++ b/src/site/ja/markdown/batch.md
@@ -0,0 +1,344 @@
+
+# Spring Batch
+
+MyBatis-Spring 1.1.0 以降では、 Spring Batch を構築するための Bean として `MyBatisPagingItemReader` 、 `MyBatisCursorItemReader` 、 `MyBatisBatchItemWriter` が用意されています。
+また、2.0.0 以降では、Java Configuration をサポートするための Builder クラスとして `MyBatisPagingItemReaderBuilder` 、 `MyBatisCursorItemReaderBuilder` 、 `MyBatisBatchItemWriterBuilder` が用意されています。
+
+NOTE
+ここで扱うのは [Spring Batch](http://static.springsource.org/spring-batch/) を使ったバッチ処理で、MyBatis の [`SqlSession`](sqlsession.html) を利用したバッチ処理ではありません。
+
+## MyBatisPagingItemReader
+
+この Bean は、MyBatis を利用してデータベースからページ単位でレコードを読み出す `ItemReader` です。
+
+結果を取得する際は `setQueryId` プロパティで指定したクエリが実行されます。1ページあたりの件数は setPageSize プロパティで指定することができます。
+`read()` メソッドが呼び出されると、必要に応じて追加のページを取得するクエリが実行されます。
+実行されるクエリでは、Reader によって提供されるページング処理を行う際に必要となるパラメーターを使って期待される結果を返す SQL 文を記述することになります(実際の SQL 文は方言依存です)。
+提供されるパラメーターは次の通りです。
+
+* `_page`: 取得対象のページ番号(最初のページは0
+* `_pagesize`: 1ページあたりの件数
+* `_skiprows`: `_page` と `_pagesize` の積
+
+これらのパラメーターは、例えば次のように SELECT 文中で指定することができます。
+
+```xml
+
+```
+
+設定例:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisPagingItemReader reader() {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+**さらに複雑な例:**
+
+```xml
+
+```
+```xml
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @StepScope
+ @Bean
+ public MyBatisPagingItemReader dateBasedCriteriaReader(
+ @Value("#{@datesParameters}") Map datesParameters) throws Exception {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(batchReadingSessionFactory())
+ .queryId("com.my.name.space.batch.ExampleMapper.queryUserInteractionsOnSpecificTimeSlot")
+ .parameterValues(datesParameters)
+ .pageSize(200)
+ .build();
+ }
+
+ @StepScope
+ @Bean
+ public Map datesParameters(
+ @Value("#{jobExecutionContext['EXTRACTION_START_DATE']}") LocalDate yesterday,
+ @Value("#{jobExecutionContext['TODAY_DATE']}") LocalDate today,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_MONTH_DATE']}") LocalDate firstDayOfTheMonth,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_PREVIOUS_MONTH_DATE']}") LocalDate firstDayOfThePreviousMonth) {
+ Map map = new HashMap<>();
+ map.put("yesterday", yesterday);
+ map.put("today", today);
+ map.put("first_day_of_the_month", firstDayOfTheMonth);
+ map.put("first_day_of_the_previous_month", firstDayOfThePreviousMonth);
+ return map;
+ }
+}
+```
+
+The previous example makes use of a few different things:
+
+* `sqlSessionFactory`: あなた自身の sessionFactory を reader に指定することができます。複数のデータベースから読み取る場合は有用かも知れません。
+* `queryId`: レコード取得時に実行されるクエリの ID を指定します。異なるネームスペースに属するクエリを指定する場合はネームスペースの指定を忘れないようにしてください。
+* `parameterValues`: クエリ実行時に使用する追加のパラメーターを Map 形式で渡すことができます。上の例では Spring が `jobExecutionContext` から SpEL 式を使って取得した値をもとに構築した `Map` を指定しています。
+ MyBatis の Mapper ファイルでは `Map` のキーをパラメーター名として指定します(例: *yesterday* を指定する場合は `#{yesterday,jdbcType=TIMESTAMP}` のように指定します)。
+ `jobExecutionContext` と Spring EL 式を利用するため、`Map` および `Reader` はどちらも `step` スコープ内で構築されているという点に注意してください。
+ また、MyBatis の `TypeHandler` が正しく設定されていれば、この例のように JodaTime のようなカスタムのインスタンスを引数として渡すこともできます。
+* `pageSize`: バッチ処理のチャンクサイズを指定します。
+
+## MyBatisCursorItemReader
+
+This bean is an `ItemReader` that reads records from a database using a cursor.
+
+NOTE
+To use this bean you need at least MyBatis 3.4.0 or a newer version.
+
+It executes the query specified as the `setQueryId` property to retrieve requested data by using the method `selectCursor()`.
+Each time a `read()` method is called it will return the next element of the cursor until no more elements are left.
+
+The reader will use a separate connection so the select statement does no participate in any transactions created as part of the step processing.
+
+When using the cursor you can just execute a regular query:
+
+```xml
+
+```
+
+Follows below a sample configuration snippet:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisCursorItemReader reader() {
+ return new MyBatisCursorItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+## MyBatisBatchItemWriter
+
+`SqlSessionTemplate` のバッチ機能を使って渡された一連のアイテムを処理する `ItemWriter` です。 `SqlSessionFactory` は `ExecutorType.BATCH` を使って設定する必要があります。
+
+`write()` の呼び出し時に実行するステートメントの ID を指定しておく必要があります。 `write()` はトランザクション内で呼び出されることを前提としています。
+
+設定例:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("com.my.name.space.batch.EmployeeMapper.updateEmployee")
+ .build();
+ }
+}
+```
+
+**`ItemReader`を使用して読み込んだアイテムを任意のパラメータオブジェクトへ変換する**
+
+デフォルトの動作では、`MyBatisBatchItemWriter` は `ItemReader` を使用して読みこんだアイテム (または `ItemProcessor` によって変換したアイテム)を、そのままMyBatis(`SqlSession` の `update` メソッド)のパラメーターオブジェクトとして渡します。
+もしMyBatisへ渡すパラメーターオブジェクトをカスタマイズしたい場合は、`itemToParameterConverter` オプションを利用することで実現するすることができます。
+たとえば、`itemToParameterConverter` オプションを使用すると、 アイテムオブジェクト以外のオブジェクトをMyBatisへ渡すことができます。
+以下にサンプルを示します。
+
+まず、任意のパラメータオブジェクトに変換するためのコンバータクラス(またはファクトリメソッド)を作成します。以下のサンプルではファクトリメソッドを使用します。
+
+```java
+public class ItemToParameterMapConverters {
+ public static Converter> createItemToParameterMapConverter(String operationBy, LocalDateTime operationAt) {
+ return item -> {
+ Map parameter = new HashMap<>();
+ parameter.put("item", item);
+ parameter.put("operationBy", operationBy);
+ parameter.put("operationAt", operationAt);
+ return parameter;
+ };
+ }
+}
+```
+
+つぎに, SQLマッピングを書きます。
+
+```xml
+
+```
+
+さいごに, `MyBatisBatchItemWriter` の設定を行います。
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() throws Exception {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("org.mybatis.spring.sample.mapper.PersonMapper.createPerson")
+ .itemToParameterConverter(createItemToParameterMapConverter("batch_java_config_user", LocalDateTime.now()))
+ .build();
+ }
+}
+```
+
+```xml
+
+
+
+
+
+
+
+
+
+
+```
+
+**Composite Writer を使って複数のテーブルに書き込む(注意事項あり)**
+
+このテクニックを使うには MyBatis 3.2 以降が必要です。それ以前のバージョンには [問題](http://code.google.com/p/mybatis/issues/detail?id=741) があるため、Writer が期待通りに動作しません。
+
+まず、*Interaction* と1対1の関係にある *InteractionMetadata* と、これらとは独立した *VisitorInteraction* および *CustomerInteraction* を保持する Item クラスを用意します。
+
+```java
+public class InteractionRecordToWriteInMultipleTables {
+ private final VisitorInteraction visitorInteraction;
+ private final CustomerInteraction customerInteraction;
+ private final Interaction interaction;
+ // ...
+}
+```
+```java
+public class Interaction {
+ private final InteractionMetadata interactionMetadata;
+}
+```
+
+`CompositeItemWriter` の設定では、それぞれのオブジェクトの writer を順番に呼び出すように設定します。
+この例では *Interaction* をアップデートするためのキーを取得するため、*InteractionMetadata* を先に書き込む必要があります。
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public CompositeItemWriter> interactionsItemWriter() {
+ CompositeItemWriter compositeItemWriter = new CompositeItemWriter();
+ List> writers = new ArrayList<>(4);
+ writers.add(visitorInteractionsWriter());
+ writers.add(customerInteractionsWriter());
+ writers.add(interactionMetadataWriter());
+ writers.add(interactionWriter());
+ compositeItemWriter.setDelegates(writers);
+ return compositeItemWriter;
+ }
+}
+```
+
+それぞれの writer を必要に応じて設定します。例えば *Interaction* と *InteractionMetadata* の設定は次のようになります。
+
+```xml
+
+```
+```xml
+
+```
+
+reader の場合と同様、 `statementId` はネームスペースを含むステートメント ID です。
+
+Mapper ファイルにステートメントを定義します。
+
+```xml
+
+
+
+```
+```xml
+
+
+
+```
+
+はじめに `insertInteractionMetadata` が呼ばれ、その際に取得した主キーを使って親となる `Interaction` を `insertInteraction` を使って書き込むことができます。
+
+***JDBC ドライバによって動作が異なるので注意が必要です。例えば MySQL の JDBC ドライバは作成された全ての行の ID を返しますが、H2 バージョン 1.3.168 ではバッチモードでも最後に作成された行の ID のみが返されます。***
diff --git a/src/site/ja/markdown/boot.md b/src/site/ja/markdown/boot.md
new file mode 100644
index 0000000000..0243b87200
--- /dev/null
+++ b/src/site/ja/markdown/boot.md
@@ -0,0 +1,4 @@
+
+# Using Spring Boot
+
+詳細は [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) のドキュメントを参照してください。
diff --git a/src/site/ja/markdown/factorybean.md b/src/site/ja/markdown/factorybean.md
new file mode 100644
index 0000000000..f1fef7443c
--- /dev/null
+++ b/src/site/ja/markdown/factorybean.md
@@ -0,0 +1,99 @@
+
+# SqlSessionFactoryBean
+
+基となる MyBatis では、`SqlSessionFactory` をビルドする際 `SqlSessionFactoryBuilder` を使いましたが、MyBatis-Spring では、`SqlSessionFactoryBean` を使います。
+
+## 設定
+
+Spring の XML 設定ファイルに次の Bean を定義することで Factory Bean を生成することができます。
+
+```xml
+
+
+
+```
+
+`SqlSessionFactoryBean` は Spring の `FactoryBean` インターフェイス([the Spring documentation(Core Technologies -Customizing instantiation logic with a FactoryBean-](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-extension-factorybean) を参照してください)を実装しています。
+これはつまり、最終的に Spring が生成するのは `SqlSessionFactoryBean` ではなく、Factory の `getObject()` メソッドによって返されるオブジェクトであるということです。
+上記の設定では、Spring は `SqlSessionFactory` を生成し、`sqlSessionFactory` という名前の Bean として登録します。
+これに相当する Java のコードは下記のようになるでしょう。
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+通常 MyBatis-Spring を使う場合、`SqlSessionFactoryBean` や対応する `SqlSessionFactory` を直接利用する必要はありません。
+`SqlSessionFactory` は `MapperFactoryBean` や `SqlSessionDaoSupport` を継承した他の DAO にインジェクト(注入)されます。
+
+## プロパティ
+
+`SqlSessionFactory` で必須のプロパティは JDBC の `DataSource` のみです。 どのような `DataSource` でも構いません。Spring でデータベース接続を定義する通常の手順で定義してください。
+
+`configLocation` は、MyBatis の XML 設定ファイルの場所を指定する際に使用します。これは、例えば基になる MyBatis の設定の一部を変更したい場合などに必要となります。
+よくあるのは `>settings>` や `` などの設定です。
+
+ここで指定する設定ファイルは、完全な MyBatis 設定ファイルである必要はありません。 環境、データソース、MyBatis のトランザクションマネージャーに関する設定は**無視されます**。
+`SqlSessionFactoryBean` は、独自にカスタマイズした MyBatis `Environment` を生成し、必要に応じてこれらの値を設定するようになっています。
+
+設定ファイルの指定が必要とされるもう一つの例は、MyBatis の Mapper XML ファイルが Mapper クラスとは別のクラスパスに存在する場合です。
+このような構成にする場合、次のどちらかの方法で設定することができます。最初の方法は、MyBatis の設定ファイルの `` で各 XML ファイルのクラスパスを指定する方法です。
+そしてもう一つは、Factory Bean の `mapperLocations` を使った方法です。
+
+`mapperLocations` プロパティは Resource Location のリストを取り、ここで MyBatis の XML Mapper ファイルの場所を指定することができます。
+Ant スタイルのパターン文字列を使って特定のディレクトリ内の全ファイルを指定したり、内包するディレクトリを再帰的に検索対象にすることもできます。次の例を見てください。
+
+```xml
+
+
+
+
+```
+
+このように指定すると、クラスパス内の `sample.config.mappers` パッケージと、そのサブパッケージに含まれる全ての MyBatis Mapper XML ファイルがロードされます。
+
+Container-Managed トランザクションを利用する環境では、`transactionFactoryClass` プロパティが必須となります。「トランザクション」章の該当する節を参照してください。
+
+複数のデータベースを使用する場合は、`databaseIdProvider` プロパティを設定する必要があります。
+
+```xml
+
+
+
+ sqlserver
+ db2
+ oracle
+ mysql
+
+
+
+```
+```xml
+
+
+
+
+
+```
+
+NOTE
+1.3.0より、`configuration` プロパティが追加されました。このプロパティには、MyBatisのXML設定ファイルを使わずに`Configuration`インスタンスを直接指定することができます。
+次の例を見てください。
+
+```xml
+
+
+
+
+
+
+
+
+```
diff --git a/src/site/ja/markdown/getting-started.md b/src/site/ja/markdown/getting-started.md
new file mode 100644
index 0000000000..d1ed42e4c1
--- /dev/null
+++ b/src/site/ja/markdown/getting-started.md
@@ -0,0 +1,100 @@
+
+# スタートガイド
+
+この章では、MyBatis-Spring のインストール・設定手順と、トランザクション処理を含むシンプルなアプリケーションの構築する方法について説明します。
+
+## インストール
+
+MyBatis-Spring を使うためには、 `mybatis-spring-${project.version}.jar` と依存するライブラリをクラスパスに追加するだけで OK です。
+
+Maven をお使いの場合は、 pom.xml に次の dependency を追加してください。
+
+```xml
+
+ org.mybatis
+ mybatis-spring
+ ${project.version}
+
+```
+
+## クイックセットアップ
+
+MyBatis と Spring を組み合わせて使う場合、Spring の Application Context 内に少なくとも `SqlSessionFactory` と一つ以上の Mapper インターフェイスを定義する必要があります。
+
+MyBatis-Spring では `SqlSessionFactory` の生成に `SqlSessionFactoryBean` を使います。この Factory Bean を設定するため、Spring の 設定ファイルに次の Bean を追加してください。
+
+```xml
+
+
+
+```
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() throws Exception {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+`SqlSessionFactory` が `DataSource` を必要としている点に注意してください。どのような `DataSource` でも構いません。通常の手順で設定してください。
+
+Mapper インターフェイスが次のように定義されている場合...
+
+```java
+public interface UserMapper {
+ @Select("SELECT * FROM users WHERE id = #{userId}")
+ User getUser(@Param("userId") String userId);
+}
+```
+
+`MapperFactoryBean` を使ってこのインターフェイスを Spring に登録する場合、以下のように設定します。
+
+```xml
+
+
+
+
+```
+
+ここで指定した Mapper は、実装クラスではなく **インターフェイス** である必要がありますので注意してください。
+この例では、アノテーションを使って SQL を指定していますが、Mapper XML ファイルを使うこともできます。
+
+上記のように設定しておけば、あとは他の Spring Bean と同様にビジネス/サービス層のオブジェクトにインジェクト(注入)することができます。
+`MapperFactoryBean` は `SqlSession` の生成とクローズを行います。
+もし Spring のトランザクション内で実行された場合は、トランザクション終了時にセッションがコミットあるいはロールバックされます。
+最後にもう一点、全ての例外は Spring の `DataAccessException` に変換されます。
+
+Java Configurationを使用する場合:
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public UserMapper userMapper() throws Exception {
+ SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory());
+ return sqlSessionTemplate.getMapper(UserMapper.class);
+ }
+}
+```
+
+MyBatis のデータメソッドは、一行だけで実行可能となります。
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
diff --git a/src/site/ja/markdown/index.md b/src/site/ja/markdown/index.md
new file mode 100644
index 0000000000..0c6adb2296
--- /dev/null
+++ b/src/site/ja/markdown/index.md
@@ -0,0 +1,52 @@
+
+# イントロダクション
+
+## MyBatis-Spring とは?
+
+MyBatis-Spring によって MyBatis と Spring をシームレスに連携させることができます。このライブラリを使えば、MyBatis のステートメントを Spring のトランザクション内で実行することもできますし、Mapper や `SqlSession` の生成、他の Bean への注入、MyBatis の例外から Spring の `DataAccessException` への変換、さらには MyBatis や Spring, MyBatis-Spring に依存しないコードでアプリケーションを構築することも可能になります。
+
+## 動機
+
+Spring バージョン 2 は iBATIS バージョン 2 しかサポートしていません。Spring 3 の開発時に MyBatis 3 への対応が検討されました(こちらの [チケット](https://jira.springsource.org/browse/SPR-5991) 参照)が、Spring 3 が MyBatis 3 よりも前に正式リリースを迎えたため、残念ながら実装は見送られました。Spring 開発陣としては、未リリースの MyBatis 3 に合わせたコードをリリースしたくなかったという事情があり、Spring 側での正式対応は保留となっていました。MyBatis コミュニティの中で Spring 対応への要望が強かったため、有志によって Spring との連携を行う MyBatis のサブプロジェクトが立ち上げられました。
+
+## 動作条件
+
+MyBatis-Spring を利用するためには、MyBatis と Spring の用語について理解しておくことが重要です。このドキュメントには MyBatis や Spring についての説明や基本設定といった情報は含まれていません。
+
+MyBatis-Spring は以下のバージョンを必要とします。
+
+| MyBatis-Spring | MyBatis | Spring Framework | Spring Batch | Java |
+| --- | --- | --- | --- | --- |
+| **2.0** | 3.5+ | 5.0+ | 4.0+ | Java 8+ |
+| **1.3** | 3.4+ | 3.2.2+ | 2.1+ | Java 6+ |
+
+## 謝辞
+
+このプロジェクトの実現にご協力頂いた次の方々に感謝します(アルファベット順):
+Eduardo Macarron, Hunter Presnall, Putthiphong Boonphong(コーディング、テスト、ドキュメント作成);
+Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan, Tomas Pinos(コントリビューション);
+Simone Tripodi(メンバーを集め、MyBatis のサブプロジェクトとしてまとめてくれました)
+このプロジェクトは彼らの協力なしには実現できなかったでしょう。
+
+## このドキュメントの改善にご協力ください...
+
+このドキュメントの中で誤りや特定の機能に関する記述が抜けていることに気づいたら、詳しく調べてドキュメントを更新して頂けると助かります。
+
+このマニュアルのソースは markdown 形式で、[プロジェクトの Git リポジトリ](https://github.com/mybatis/spring/tree/master/src/site) で配布されています。
+リポジトリをフォーク、それらを更新します、とプルリクエストを送信します。
+
+このドキュメントを必要としている人、つまりあなたこそが最高の著者なのです!
+
+## Translations
+
+MyBatis-Spring は以下の言語の翻訳を用意しています。
+
+
- This bean is an ItemReader that reads records from a database using a cursor.
-
-
-
- NOTE To use this bean you need at least MyBatis 3.4.0 or a newer version.
-
-
-
- It executes the query specified as the setQueryId property to retrieve requested data
- by using the method selectCursor().
- Each time a read() method is called it will return the next element of the cursor until no more
- elements are left.
-
-
-
- The reader will use a separate connection so the select statement does no participate in any transactions created
- as part of the step processing.
-
-
-
When using the cursor you can just execute a regular query:
-
- SELECT id, name, job FROM employees ORDER BY id ASC
-]]>
-
-
- NOTE
- See JPetstore 6 demo to know about how to use Spring with a full web application server.
-
-
-
- You can check out sample code from the MyBatis-Spring repo:
-
-
- Any of the samples can be run with JUnit 5.
-
-
- The sample code shows a typical design where a transactional service gets domain objects from a data access layer.
-
-
- FooService.java acts as the service:
-
-
-
- It is a transactional bean, so when the method is called, the transaction is started
- and the transaction is committed when the method ends without throwing an uncaught exception.
- Notice that transactional behaviour is configured with the
- @Transactional
- attribute. This is not required; any other way provided by Spring can be used to demarcate
- your transactions.
-
-
- This service calls a data access layer built with MyBatis. This layer
- consists on a just an interface UserMapper.java
- that will be used with a dynamic proxy built by MyBatis at
- runtime and injected into the service by Spring.
-
-
-
- Note that, for the sake of simplicity we used the interface UserMapper.java for the DAO scenario
- where a DAO is built with an interface and a implementation though in this case it would have been more
- adequate to use an interface called UserDao.java instead.
-
-
- We will see different ways to find the mapper interface, register it to Spring and inject it into the service bean:
-
-
-
Scenarios
-
-
-
Sample test
-
Description
-
-
-
-
-
- SampleMapperTest.java
-
-
- Shows you the base configuration based on a MapperFactoryBean
- that will dynamically build an implementation for UserMapper
-
-
-
-
- SampleScannerTest.java
-
-
- Shows how to use the MapperScannerConfigurer so all the mappers in a project are autodiscovered.
-
-
-
-
- SampleSqlSessionTest.java
-
-
- Shows how to hand code a DAO using a Spring managed SqlSession
- and providing your own implementation UserDaoImpl.java.
-
-
-
-
- SampleEnableTest
-
-
- Shows how to use Spring's @Configuration with the @MapperScann annotation so
- mappers are autodiscovered.
-
-
-
-
- SampleNamespaceTest
-
-
- Shows how to use the custom MyBatis XML namespace.
-
-
-
-
- SampleJavaConfigTest.java
-
-
- Shows how to use Spring's @Configuration to create MyBatis beans manually.
-
-
-
-
- SampleJobJavaConfigTest.java
-
-
- Shows how to use ItemReader and ItemWriter on Spring Batch using Java Configuration.
-
-
-
-
- SampleJobXmlConfigTest.java
-
-
- Shows how to use ItemReader and ItemWriter on Spring Batch using XML Configuration.
-
-
-
-
-
- Please take a look at the different applicationContext.xml files to see MyBatis-Spring in action.
-
-
-
-
diff --git a/src/site/ko/markdown/README.md b/src/site/ko/markdown/README.md
new file mode 100644
index 0000000000..4e31a121bc
--- /dev/null
+++ b/src/site/ko/markdown/README.md
@@ -0,0 +1,18 @@
+# 목차
+
+이 페이지는 GitHub에서 인덱스를 렌더링하기위한 것입니다.
+
+> **NOTE:**
+>
+> 링크 대상은 maven-site-plugin을 사용하여 html로 변환된다는 가정하에 지정되므로 GitHub의 렌더링에서 끊어진 앵커가 있습니다.
+
+* [소개](./index.md)
+* [시작하기](./getting-started.md)
+* [SqlSessionFactoryBean](./factorybean.md)
+* [트랜잭션](./transactions.md)
+* [SqlSession 사용](./sqlsession.md)
+* [매퍼 주입](./mappers.md)
+* [Spring Boot](./boot.md)
+* [MyBatis API 사용](./using-api.md)
+* [Spring Batch](./batch.md)
+* [샘플 코드](./sample.md)
diff --git a/src/site/ko/markdown/batch.md b/src/site/ko/markdown/batch.md
new file mode 100644
index 0000000000..29ec3f6df6
--- /dev/null
+++ b/src/site/ko/markdown/batch.md
@@ -0,0 +1,353 @@
+
+# Spring Batch
+
+마이바티스 스프링 연동모듈의 1.1.0버전에서는 스프링 배치 애플리케이션을 만들기 위해 두개의 빈을 제공한다.
+두개의 빈은 `MyBatisPagingItemReader` 와 `MyBatisCursorItemReader` 와 MyBatisBatchItemWriter이다.
+
+또한 2.0.0 버전에서는 Java Configuration 을 지원하는 다음의 세 가지 Builder class 를 제공한다.
+`MyBatisPagingItemReaderBuilder`, `MyBatisCursorItemReaderBuilder` 그리고 `MyBatisBatchItemWriterBuilder` 이다.
+
+중요
+이 문서는 [스프링 배치](http://static.springsource.org/spring-batch/) 에 대한 것으로 마이바티스 배치 `SqlSession` 을 다루지는 않는다.
+배치 세션에 대해서는 [SqlSession 사용](sqlsession.html) 에서 좀더 다루었다.
+
+# MyBatisPagingItemReader
+
+이 빈은 마이바티스로 페이지를 처리하는 형태로 데이터베이스 데이터를 읽어오는 `ItemReader`이다.
+
+요청된 데이터를 가져오기 위해 `setQueryId` 프로퍼티에 명시된 쿼리를 실행한다.
+쿼리는 `setPageSize` 프로퍼티에 명시된 크기만큼 데이터를 가져오도록 실행된다.
+`read()` 메서드를 사용하면 필요할 때 현재 위치에서 정해진 수 만큼 더 추가 데이터를 가져온다.
+reader는 몇가지의 표준적인 쿼리 파라미터를 제공하고 명명된 쿼리의 SQL은 요청된 크기만큼의 데이터를 만들기 위해 파라미터의 일부 혹은 모두 사용한다.
+여기서 사용가능한 파라미터이다.
+
+* `_page`: 읽을 페이지 수(0부터 시작)
+* `_pagesize`: 페이지의 크기, 이를테면 리턴하는 로우 수
+* `_skiprows`: `_page` 와 `_pagesize`의 결과
+
+각각의 파라미터는 selet구문에서 다음처럼 매핑될 수 있다.
+
+```xml
+
+```
+
+다음의 코드는 샘플 설정이다.
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisPagingItemReader reader() {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+**좀더 복잡한 예제를 보자.**
+
+```xml
+
+```
+```xml
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @StepScope
+ @Bean
+ public MyBatisPagingItemReader dateBasedCriteriaReader(
+ @Value("#{@datesParameters}") Map datesParameters) throws Exception {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(batchReadingSessionFactory())
+ .queryId("com.my.name.space.batch.ExampleMapper.queryUserInteractionsOnSpecificTimeSlot")
+ .parameterValues(datesParameters)
+ .pageSize(200)
+ .build();
+ }
+
+ @StepScope
+ @Bean
+ public Map datesParameters(
+ @Value("#{jobExecutionContext['EXTRACTION_START_DATE']}") LocalDate yesterday,
+ @Value("#{jobExecutionContext['TODAY_DATE']}") LocalDate today,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_MONTH_DATE']}") LocalDate firstDayOfTheMonth,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_PREVIOUS_MONTH_DATE']}") LocalDate firstDayOfThePreviousMonth) {
+ Map map = new HashMap<>();
+ map.put("yesterday", yesterday);
+ map.put("today", today);
+ map.put("first_day_of_the_month", firstDayOfTheMonth);
+ map.put("first_day_of_the_previous_month", firstDayOfThePreviousMonth);
+ return map;
+ }
+}
+```
+
+앞의 예제와는 몇가지 차이점이 있다.
+
+* `sqlSessionFactory`: reader에 별도로 구현한 sessionFactory를 지정할 수 있다. 이 옵션은 다양한 데이터베이스에서 데이터를 읽을때 유용하다.
+* `queryId`: 여러개의 테이블에서 데이터를 읽어야 하고 서로 다른 쿼리를 사용한다면 서로다른 네임스페이스를 가진 매퍼 파일을 사용하는게 좋을수 있다. 쿼리를 알아볼때, 매퍼 파일의 네임스페이스를 잊지 말아야 한다.
+* `parameterValues`: 이 맵을 사용해서 추가로 파라미터를 전달할 수 있다. 위 예제는 `jobExecutionContext`에서 값들을 가져오는 SpEL표현식을 사용하는 맵을 사용하고 있다.
+ 맵의 키는 매퍼파일에서 마이바티스가 사용할 것이다. (예: *yesterday* 는 `#{yesterday,jdbcType=TIMESTAMP}` 로 사용될수 있다.).
+ 맵과 reader 모두 `jobExecutionContext`에서 SpEL표현식을 사용하기 위해 `step` 스코프를 사용한다. 마이바티스의 타입핸들러가 제대로 설정이 되었다면 JodaTime날짜를 맵을 사용해서 파라미터로 넘길수 있다.
+* `pageSize`: 배치가 청크크기가 지정된 형태로 처리가 되면 reader에 이 값을 전달하는게 적절하다.
+
+## MyBatisCursorItemReader
+
+이 빈은 cursor 를 사용하여 데이터베이스에서 레코드를 읽는 `ItemReader` 이다.
+
+중요
+이 빈을 사용하려면 최소한 MyBatis 3.4.0 이나 그 이상이어야 한다.
+
+`setQueryId` 속성으로 지정된 쿼리를 실행하여 `selectCursor()` 메서드를 사용하여 요청 된 데이터를 검색한다. `read()` 메서드가 호출 될 때마다 요소가 더 이상 남아 있지 않을 때까지 cursor 의 다음 요소를 반환한다.
+
+reader 는 별도의 connection 을 사용하므로 select 문은 step processing 일부로 생성된 트랜잭션에 속하지 않는다.
+
+cursor 를 사용할 때 다음과 같이 일반 쿼리를 실행할 수 있다.
+
+```xml
+
+```
+
+아래는 샘플 설정이다.
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisCursorItemReader reader() {
+ return new MyBatisCursorItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+# MyBatisBatchItemWriter
+
+모든 아이템을 배치로 구문을 일괄실행하기 위해 `SqlSessionTemplate`에서 배치로 작업을 처리하는 `ItemWriter`이다. `SqlSessionFactory`는 `BATCH` 실행자로 설정할 필요가 있다.
+
+사용자는 `write()` 메서드가 호출될때 실행될 매핑구문 아이디를 제공해야 한다. `write()` 메서드는 트랜잭션내에서 호출되는 것으로 예상된다.
+
+다음의 코드는 샘플설정이다.
+
+```xml
+
+
+
+
+```
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("com.my.name.space.batch.EmployeeMapper.updateEmployee")
+ .build();
+ }
+}
+```
+
+
+**Converting a item that read using ItemReader to an any parameter object:**
+
+By default behavior, the `MyBatisBatchItemWriter` passes a item that read using `ItemReader` (or convert by `ItemProcessor`) to the MyBatis(`SqlSession#update()`) as the parameter object.
+If you want to customize a parameter object that passes to the MyBatis, you can realize to use the `itemToParameterConverter` option.
+For example using `itemToParameterConverter` option, you can passes any objects other than the item object to the MyBatis.
+Follows below a sample:
+
+At first, you create a custom converter class (or factory method). The following sample uses a factory method.
+
+```java
+public class ItemToParameterMapConverters {
+ public static Converter> createItemToParameterMapConverter(String operationBy, LocalDateTime operationAt) {
+ return item -> {
+ Map parameter = new HashMap<>();
+ parameter.put("item", item);
+ parameter.put("operationBy", operationBy);
+ parameter.put("operationAt", operationAt);
+ return parameter;
+ };
+ }
+}
+```
+
+At next, you write a sql mapping.
+
+```xml
+
+```
+
+At last, you configure the `MyBatisBatchItemWriter`.
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() throws Exception {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("org.mybatis.spring.sample.mapper.PersonMapper.createPerson")
+ .itemToParameterConverter(createItemToParameterMapConverter("batch_java_config_user", LocalDateTime.now()))
+ .build();
+ }
+}
+```
+
+```xml
+
+
+
+
+
+
+
+
+
+
+```
+
+**여러개의 테이블에 데이터를 쓰려면 한꺼번에 처리할 수 있도록 만든 writer(몇가지 규칙을 가지고)를 사용하자.**
+
+이 기능은 마이바티스 3.2이상에서만 사용할 수 있다. 이전의 버전에서는 예상과 다르게 동작하는데 그 내용은 [이슈](http://code.google.com/p/mybatis/issues/detail?id=741)를 참고하면 된다.
+
+배치가 관계를 가지는 데이터나 여러개의 데이터베이스를 다루는 것처럼 복잡한 데이터를 작성할때 필요하다면 insert구문이 한개에 테이블에만 데이터를 넣을수 있다는 사실만 피하면 가능하기도 하다.
+이런 복잡한 데이터를 처리하기 위해 writer가 작성하는 아이템(Item)을 준비해야 한다. 다음의 기술을 사용하면 단순한 관계를 가진 데이터나 관계가 없는 테이블을 처리하는 아이템에서 사용할 수 있다.
+
+이러한 방법으로 스프링 배치 아이템은 모든 레코드를 *다룰것이다*.
+여기에는 1:1 *관계*를 가지는 *InteractionMetadata*, 관계가 없는 두개의 로우는 *VisitorInteraction* 와 *CustomerInteraction*이 있다.
+이 각각의 객체는 다음과 같이 볼수 있다.
+
+```java
+public class InteractionRecordToWriteInMultipleTables {
+ private final VisitorInteraction visitorInteraction;
+ private final CustomerInteraction customerInteraction;
+ private final Interaction interaction;
+ // ...
+}
+```
+```java
+public class Interaction {
+ private final InteractionMetadata interactionMetadata;
+}
+```
+
+그리고 스프링 설정에는 각각의 레코드를 처리하기위해 특별히 설정된 전용(delegates) writer를 사용하는 `CompositeItemWriter`가 있다.
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+```
+```java
+@Bean
+@Configuration
+public class BatchAppConfig {
+ public CompositeItemWriter> interactionsItemWriter() {
+ CompositeItemWriter compositeItemWriter = new CompositeItemWriter();
+ List> writers = new ArrayList<>(4);
+ writers.add(visitorInteractionsWriter());
+ writers.add(customerInteractionsWriter());
+ writers.add(interactionMetadataWriter());
+ writers.add(interactionWriter());
+ compositeItemWriter.setDelegates(writers);
+ return compositeItemWriter;
+ }
+}
+```
+
+각각의 전용(delegate) writer는 필요할 만큼 설정할 수 있다. 예를들면 *Interaction* 과 *InteractionMetadata*를 위한 writer가 있다.
+
+```xml
+
+```
+```xml
+
+```
+
+reader와 동일하게 `statementId`는 네임스페이스를 가진 구문을 가리킬수 있다.
+
+매퍼 파일에서 구문은 다음과 같은 방법으로 각각의 레코드를 위해 만들어져있다.
+
+```xml
+
+
+
+```
+```xml
+
+
+
+```
+
+먼저 `insertInteractionMetadata`가 호출될것이고 update구문은 jdbc드라이버에 의해(`keyProperty` 와 `keyColumn`) 생성된 아이디들을 리턴하기 위해 설정되었다.
+`InteractionMetadata` 객체가 이 쿼리에 의해 업데이트되면 다음의 쿼리는 `insertInteraction`를 통해 상위객체인 `Interaction`를 작성하기 위해 사용될수 있다.
+
+***방금 언급한 내용에 관련하여 JDBC드라이버가 똑같이 동작하지 않을수 있다.
+이 글을 쓰는 시점에 H2 드라이버 1.3.168버전(`org.h2.jdbc.JdbcStatement#getGeneratedKeys`를 보라)만 배치모드에서 마지막 인덱스를 리턴한다.
+반면에 MySQL 드라이버는 기대한 것과 동일하게 동작하고 모든 아이디를 리턴한다.***
diff --git a/src/site/ko/markdown/boot.md b/src/site/ko/markdown/boot.md
new file mode 100644
index 0000000000..7e932a7fa6
--- /dev/null
+++ b/src/site/ko/markdown/boot.md
@@ -0,0 +1,4 @@
+
+# 스프링 부트 사용하기
+
+자세한 내용은 [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) 하위 프로젝트 문서를 참조하십시오.
diff --git a/src/site/ko/markdown/factorybean.md b/src/site/ko/markdown/factorybean.md
new file mode 100644
index 0000000000..e0a79081ad
--- /dev/null
+++ b/src/site/ko/markdown/factorybean.md
@@ -0,0 +1,97 @@
+
+# SqlSessionFactoryBean
+
+마이바티스만 사용하면, `SqlSessionFactory`는 `SqlSessionFactoryBuilder`를 사용해서 생성한다.
+마이바티스 스프링 연동모듈에서는, `SqlSessionFactoryBean`가 대신 사용된다.
+
+## 설정
+
+팩토리 빈을 생성하기 위해, 스프링 XML설정파일에 다음설정을 추가하자.
+
+```xml
+
+
+
+```
+
+`SqlSessionFactoryBean` 은 스프링의 `FactoryBean` 인터페이스를 구현(see [the Spring documentation(Core Technologies -Customizing instantiation logic with a FactoryBean-)](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-extension-factorybean))한다는 점을 알아야 한다.
+이 설정은 스프링이 `SqlSessionFactoryBean` 자체를 생성하는 것이 **아니라** 팩토리에서 `getObject()` 메서드를 호출한 결과를 리턴한다는 것을 의미한다.
+이 경우, 스프링은 애플리케이션 시작 시점에 `SqlSessionFactory`를 빌드하고 `sqlSessionFactory` 라는 이름으로 저장한다. 자바에서 코드로 표현하면 아래와 같다.
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+일반적인 마이바티스 스프링 사용법에서는, `SqlSessionFactoryBean`이나 관련된 `SqlSessionFactory`를 직접 사용할 필요가 없다.
+대신 세션 팩토리가 `MapperFactoryBean`나 `SqlSessionDaoSupport`를 확장하는 다른 DAO에 주입될것이다.
+
+## 속성
+
+`SqlSessionFactory`는 JDBC `DataSource`의 필수 프로퍼티가 필요하다. 어떤 `DataSource`라도 상관없고 다른 스프링 데이터베이스 연결처럼 설정되어야만 한다.
+
+하나의 공통적인 프로퍼티는 마이바티스 XML설정파일의 위치를 지정하기 위해 사용되는 `configLocation`이다. 이 프로퍼티를 설정하는 것은 디폴트 설정을 가진 마이바티스 설정을 변경해야 할 경우 뿐이다.
+대개는 ``과 `` 섹션을 변경하는 경우이다.
+
+설정파일이 마이바티스 설정을 완전히 다룰 필요는 없다. 어떤 환경, 어떤 데이터소스 그리고 마이바티스 트랜잭션 관리자가 **무시**될수도 있다.
+`SqlSessionFactoryBean` 는 필요에 따라 이 값들을 설정하여 자체적인 MyBatis `Environment` 를 만든다.
+
+설정파일이 필요한 다른 이유는 마이바티스 XML파일이 매퍼 클래스와 동일한 클래스패스에 있지 않은 경우이다. 이 설정을 사용하면 두가지 옵션이 있다.
+첫번째는 마이바티스 설정파일에 `` 섹션을 사용해서 XML파일의 클래스패스를 지정하는 것이다. 두번째는 팩토리 빈의 `mapperLocations` 프로퍼티를 사용하는 것이다.
+
+`mapperLocations` 프로퍼티는 매퍼에 관련된 자원의 위치를 나열한다. 이 프로퍼티는 마이바티스의 XML매퍼 파일들의 위치를 지정하기 위해 사용될 수 있다.
+디렉터리 아래 모든 파일을 로드하기 위해 앤트(Ant) 스타일의 패턴을 사용할수도 있고 가장 상위 위치를 지정하는 것으로 재귀적으로 하위 경로를 찾도록 할수도 있다. 예를 들어보면 다음과 같다.
+
+```xml
+
+
+
+
+```
+
+이 설정은 `sample.config.mappers` 패키지 아래와 그 하위 패키지를 모두 검색해서 마이바티스 매퍼 XML파일을 모두 로드할 것이다.
+
+컨테이너 관리 트랜잭션을 사용하는 환경에서 필요한 하나의 프로퍼티는 `transactionFactoryClass` 이다. 이에 관련해서는 트랜잭션을 다루는 장에서 볼수 있다.
+
+만약 multi-db 기능을 사용한다면 다음과 같이 `databaseIdProvider` 속성을 설정해야 한다.
+
+```xml
+
+
+
+ sqlserver
+ db2
+ oracle
+ mysql
+
+
+
+```
+````xml
+
+
+
+
+
+````
+
+NOTE
+1.3.0 버전 부터 `configuration` 속성이 추가되었다. 다음과 같이 MyBatis XML 설정 파일없이 `Configuration` 인스턴스를 직접 지정할 수 있습니다.
+
+```xml
+
+
+
+
+
+
+
+
+```
diff --git a/src/site/ko/markdown/getting-started.md b/src/site/ko/markdown/getting-started.md
new file mode 100644
index 0000000000..f04bde22cc
--- /dev/null
+++ b/src/site/ko/markdown/getting-started.md
@@ -0,0 +1,98 @@
+
+# 시작하기
+
+이 장은 마이바티스 스프링 연동모듈을 설치하고 셋팅하는 방법에 대해 간단히 보여준다. 그리고 트랜잭션을 사용하는 간단한 애플리케이션을 만드는 방법까지 다룰 것이다.
+
+## 설치
+
+마이바티스 스프링 연동모듈을 사용하기 위해서, 클래스패스에 `mybatis-spring-${project.version}.jar`를 포함시켜야 한다.
+
+메이븐을 사용하고 있다면 pom.xml에 다음처럼 의존성을 추가하면 된다.
+
+```xml
+
+ org.mybatis
+ mybatis-spring
+ ${project.version}
+
+```
+
+## 빠른 설정
+
+마이바티스를 스프링과 함께 사용하려면 스프링의 애플리케이션 컨텍스트에 적어도 두개를 정의해줄 필요가 있다.
+두가지는 `SqlSessionFactory`와 한개 이상의 매퍼 인터페이스이다.
+
+마이바티스 스프링 연동모듈에서, `SqlSessionFactoryBean`은 `SqlSessionFactory`를 만들기 위해 사용된다. 팩토리 빈을 설정하기 위해, 스프링 설정파일에 다음 설정을 추가하자.
+
+```xml
+
+
+
+```
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() throws Exception {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+`SqlSessionFactory`는 `DataSource`를 필요로 하는 것을 알아둘 필요가 있다. 어떤 `DataSource`도 상관없지만 다른 스프링의 데이터베이스 연결과 동일하게 설정되어야 한다.
+
+매퍼 인터페이스가 다음처럼 정의되었다고 가정해보자.
+
+```java
+public interface UserMapper {
+ @Select("SELECT * FROM users WHERE id = #{userId}")
+ User getUser(@Param("userId") String userId);
+}
+```
+
+UserMapper인터페이스는 다음처럼 `MapperFactoryBean`을 사용해서 스프링에 추가된다.
+
+```xml
+
+
+
+
+```
+
+매퍼는 **반드시** 구현체 클래스가 아닌 인터페이스로 정의되어야 한다. 예를들어, 애노테이션이 SQL을 명시하기 위해 사용되지만 마이바티스 매퍼 XML파일 또한 사용될 수 있다.
+
+한번만 설정하면, 다른 스프링 빈에 주입하는 같은 방법으로 비즈니스/서비스 객체에 매퍼를 직접 주입할 수 있다. `MapperFactoryBean`은 `SqlSession`을 생성하고 닫는 작업을 잘 다룬다.
+실행중인 스프링 트랜잭션이 있다면, 트랜잭션이 완료되는 시점에 커밋이나 롤백이 될 것이다. 마지막으로 예외가 발생하면 스프링의 `DataAccessException`예외가 발생한다.
+
+자바로 설정하면 다음과 같다.
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public UserMapper userMapper() throws Exception {
+ SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory());
+ return sqlSessionTemplate.getMapper(UserMapper.class);
+ }
+}
+```
+
+마이바티스의 데이터 관련 메서드는 호출하는 것은 한줄이면 된다.
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
diff --git a/src/site/ko/markdown/index.md b/src/site/ko/markdown/index.md
new file mode 100644
index 0000000000..393eec171f
--- /dev/null
+++ b/src/site/ko/markdown/index.md
@@ -0,0 +1,54 @@
+
+# 소개
+
+## MyBatis-Spring 은 무엇일까?
+
+마이바티스 스프링 연동모듈은 마이바티스와 스프링을 편하고 간단하게 연동한다. 이 모듈은 마이바티스로 하여금 스프링 트랜잭션에 쉽게 연동되도록 처리한다. 게다가 마이바티스 매퍼와 `SqlSession`을 다루고 다른 빈에 주입시켜준다.
+마이바티스 예외를 스프링의 `DataAccessException`로 변환하기도 하고 마이바티스, 스프링 또는 마이바티스 스프링 연동모듈에 의존성을 없애기도 한다.
+
+## 동기 부여
+
+스프링 2.x은 아이바티스 2.x만을 지원한다. 스프링 3.x에서 마이바티스 3.x를 지원하기 위한 시도가 진행중이다. (스프링의 이슈관리 시스템인 [이슈](https://jira.springsource.org/browse/SPR-5991) 를 보라.)
+불행하게도 스프링 3의 개발이 마이바티스 3.0의 정식릴리즈전에 개발이 완료되었다. 그래서 스프링팀은 릴리즈가 안된 마이바티스 코드를 함께 릴리즈하는 것을 원하지 않았고 실제적인 스프링 지원을 기다릴수밖에 없었다.
+스프링의 마이바티스 지원에 대한 관심으로 인해, 마이바티스 커뮤니티는 재결합하는 형태로 결정을 내고 대신 마이바티스의 하위 프로젝트 형태로 스프링 연동 프로젝트를 추가한다.
+
+## 필요 조건
+
+마이바티스 스프링 연동을 시작하기 전에, 마이바티스와 스프링의 용어를 맞추는 일이 굉장히 중요했다. 이 문서는 배경지식이나 기본적인 셋업방법 그리고 마이바티스와 스프링의 설정에 대한 튜토리얼등은 제공하지 않는다.
+
+MyBatis-Spring requires following versions:
+
+| MyBatis-Spring | MyBatis | Spring Framework | Spring Batch | Java |
+| --- | --- | --- | --- | --- |
+| **2.0** | 3.5+ | 5.0+ | 4.0+ | Java 8+ |
+| **1.3** | 3.4+ | 3.2.2+ | 2.1+ | Java 6+ |
+
+## 감사 인사
+
+이 프로젝트가 실제로 만들어지게 도와준 모든 특별한 분들에게 정말 감사한다.
+알파벳 순서로 보면, 코딩및 테스트 그리고 문서화를 담당했던 Eduardo Macarron, Hunter Presnall, Putthiphong Boonphong;
+그외 다양한 프로젝트 기여자인 Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan, Tomas Pinos;
+그리고 마이바티스에 하위 프로젝트로 가져올수 있도록 많은 것을 찾아준 Simone Tripodi 에게 감사한다. ;)
+이들이 없었다면 이 프로젝트는 존재하지 않았을 것이다.
+
+## 이 문서가 더 나아지도록 도와주세요…
+
+만약에 어떤 방법으로든 이 문서의 취약점이 발견되거나 기능에 대한 문서화가 빠진 부분이 보인다면, 가장 좋은 방법은 먼저 공부해서 자신만의 문서를 작성하는 것이다.
+
+이 문서의 원본은 xdoc포맷이며 [프로젝트의 Git](https://github.com/mybatis/spring/tree/master/src/site)에서 찾을 수 있다. repository 를 fork 하고, 업데이트하고 pull request 를 보내주십시오.
+
+당신처럼 이 문서를 읽는 사람들에게 이 문서의 최고의 저자가 될수 있다!
+
+## 번역
+
+사용자들은 다음의 번역문서별로 마이바티스 스프링 연동모듈에 대해 알수 있다.
+
+
+
+위 번역문서에는 없지만 자국의 언어로 문서로 보고 싶다면, 자국의 언어로 된 문서를 만들어서 우리에게 보내달라.
diff --git a/src/site/ko/markdown/mappers.md b/src/site/ko/markdown/mappers.md
new file mode 100644
index 0000000000..c56ba731ff
--- /dev/null
+++ b/src/site/ko/markdown/mappers.md
@@ -0,0 +1,184 @@
+
+# 매퍼 주입
+
+`SqlSessionDaoSupport` 나 `SqlSessionTemplate` 를 직접적으로 사용하는 데이터 접근 객체(DAO)를 생성하기 보다, 마이바티스 스프링 연동모듈은 다른 빈에 직접 주입할 수 있는 쓰레드에 안전한 매퍼를 생성할 수 있다.
+
+```xml
+
+
+
+```
+
+한번 주입하고나면 매퍼는 애플리케이션 로직에서 사용할수 있는 준비가 된다.
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
+
+이 코드를 보면 `SqlSession`이나 마이바티스 객체가 보이지 않는다. 게다가 세션을 생성하거나 열고 닫을필요도 없어보인다. 마이바티스 스프링 연동모듈이 알아서 처리할 것이다.
+
+
+## 매퍼 등록하기
+
+매퍼를 등록하는 방법은 기존의 전통적인 XML설정법을 사용하거나 새로운 3.0 이후의 자바설정(일명 `@Configuration`)을 사용하느냐에 따라 다르다.
+
+### XML설정 사용
+
+매퍼는 다음처럼 XML설정파일에 `MapperFactoryBean`을 두는 것으로 스프링에 등록된다.
+
+```xml
+
+
+
+
+```
+
+UserMapper가 매퍼 인터페이스와 같은 경로의 클래스패스에 마이바티스 XML매퍼 파일을 가지고 있다면 `MapperFactoryBean`이 자동으로 파싱할것이다.
+매퍼 XML파일을 다른 클래스패스에 두는게 아니라면 마이바티스 설정파일에 매퍼를 지정할 필요가 없다. 좀더 세부적인 정보는 `SqlSessionFactoryBean`의 [`configLocation`](factorybean.html) 프로퍼티를 살펴보자.
+
+`MapperFactoryBean`은 `SqlSessionFactory` 나 `SqlSessionTemplate`가 필요하다. `sqlSessionFactory` 와 `sqlSessionTemplate` 프로퍼티를 셋팅하면 된다.
+둘다 셋팅하면 `SqlSessionFactory`가 무시된다. 세션 팩토리 셋은 `SqlSessionTemplate`이 필요하고 `MapperFactoryBean`는 팩토리를 사용할것이다.
+
+### 자바설정 사용
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public MapperFactoryBean userMapper() throws Exception {
+ MapperFactoryBean factoryBean = new MapperFactoryBean<>(UserMapper.class);
+ factoryBean.setSqlSessionFactory(sqlSessionFactory());
+ return factoryBean;
+ }
+}
+```
+
+
+## 매퍼 스캔
+
+하나씩 매퍼를 모두 등록할 필요가 없다. 대신 클래스패스를 지정해서 마이바티스 스프링 연동모듈의 자동스캔기능을 사용할 수 있다.
+
+자동스캔을 사용하는데는 3가지 방법이 있다.
+
+* `` 엘리먼트 사용
+* `@MapperScan` 애노테이션 사용
+* 스프링 XML파일을 사용해서 `MapperScannerConfigurer`를 등록
+
+`` 와 `@MapperScan` 모두 마이바티스 스프링 연동모듈 1.2.0에서 추가된 기능이다. `@MapperScan` 은 스프링 버전이 3.1이상이어야 한다.
+
+Since 2.0.2, mapper scanning feature support a option (`lazy-initialization`) that control lazy initialization enabled/disabled of mapper bean.
+The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
+The default of this option is `false` (= not use lazy initialization). If developer want to use lazy initialization for mapper bean, it should be set to the `true` expressly.
+
+IMPORTANT
+If use the lazy initialization feature, the developer need to understand following limitations. If any of following conditions are matches, usually the lazy initialization feature cannot use on your application.
+
+* When refers to the statement of **other mapper** using ``(`@One`) and ``(`@Many`)
+* When includes to the fragment of **other mapper** using ``
+* When refers to the cache of **other mapper** using ``(`@CacheNamespaceRef`)
+* When refers to the result mapping of **other mapper** using `]]>
-
-
sqlSessionFactory: reader에 별도로 구현한 sessionFactory를 지정할 수 있다.
- 이 옵션은 다양한 데이터베이스에서 데이터를 읽을때 유용하다.
-
queryId: 여러개의 테이블에서 데이터를 읽어야 하고 서로 다른 쿼리를 사용한다면
- 서로다른 네임스페이스를 가진 매퍼 파일을 사용하는게 좋을수 있다.
- 쿼리를 알아볼때, 매퍼 파일의 네임스페이스를 잊지 말아야 한다.
-
parameterValues: 이 맵을 사용해서 추가로 파라미터를 전달할 수 있다.
- 위 예제는 jobExecutionContext에서 값들을 가져오는 SpEL표현식을 사용하는 맵을 사용하고 있다.
- 맵의 키는 매퍼파일에서 마이바티스가 사용할 것이다. (예: yesterday 는 #{yesterday,jdbcType=TIMESTAMP} 로 사용될수 있다.).
- 맵과 reader 모두 jobExecutionContext에서 SpEL표현식을 사용하기 위해 step 스코프를 사용한다.
- 마이바티스의 타입핸들러가 제대로 설정이 되었다면 JodaTime날짜를 맵을 사용해서 파라미터로 넘길수 있다.
-
pageSize: 배치가 청크크기가 지정된 형태로 처리가 되면 reader에 이 값을 전달하는게 적절하다.
-
-
-
-
-
-
- 이 빈은 cursor 를 사용하여 데이터베이스에서 레코드를 읽는 ItemReader 이다.
-
-
-
- 중요 이 빈을 사용하려면 최소한 MyBatis 3.4.0 이나 그 이상이어야 한다.
-
-
-
- setQueryId 속성으로 지정된 쿼리를 실행하여 selectCursor() 메서드를 사용하여 요청 된 데이터를 검색한다.
- read() 메서드가 호출 될 때마다 요소가 더 이상 남아 있지 않을 때까지 cursor 의 다음 요소를 반환한다.
-
-
-
- reader 는 별도의 connection 을 사용하므로 select 문은 step processing 일부로 생성된 트랜잭션에 속하지 않는다.
-
-
-
cursor 를 사용할 때 다음과 같이 일반 쿼리를 실행할 수 있다.
-
- SELECT id, name, job FROM employees ORDER BY id ASC
-]]>
-
-
Converting a item that read using ItemReader to an any parameter object:
-
-
- By default behavior, the MyBatisBatchItemWriter passes a item that read using ItemReader
- (or convert by ItemProcessor) to the MyBatis(SqlSession#update()) as the parameter object.
- If you want to customize a parameter object that passes to the MyBatis, you can realize to use the itemToParameterConverter option.
- For example using itemToParameterConverter option, you can passes any objects other than the item object to the MyBatis.
- Follows below a sample:
-
-
-
- At first, you create a custom converter class (or factory method). The following sample uses a factory method.
-
여러개의 테이블에 데이터를 쓰려면 한꺼번에 처리할 수 있도록 만든 writer(몇가지 규칙을 가지고)를 사용하자.
-
-
이 기능은 마이바티스 3.2이상에서만 사용할 수 있다. 이전의 버전에서는 예상과 다르게 동작하는데 그 내용은
- 이슈를 참고하면 된다.
-
-
배치가 관계를 가지는 데이터나 여러개의 데이터베이스를 다루는 것처럼 복잡한 데이터를 작성할때 필요하다면
- insert구문이 한개에 테이블에만 데이터를 넣을수 있다는 사실만 피하면 가능하기도 하다.
- 이런 복잡한 데이터를 처리하기 위해 writer가 작성하는 아이템(Item)을 준비해야 한다.
- 다음의 기술을 사용하면 단순한 관계를 가진 데이터나 관계가 없는 테이블을 처리하는 아이템에서 사용할 수 있다.
-
-
이러한 방법으로 스프링 배치 아이템은 모든 레코드를 다룰것이다.
- 여기에는 1:1 관계를 가지는 InteractionMetadata,
- 관계가 없는 두개의 로우는 VisitorInteraction 와 CustomerInteraction이 있다.
- 이 각각의 객체는 다음과 같이 볼수 있다.
-
-
-
-
그리고 스프링 설정에는 각각의 레코드를 처리하기위해 특별히 설정된
- 전용(delegates) writer를 사용하는 CompositeItemWriter가 있다.
각각의 전용(delegate) writer는 필요할 만큼 설정할 수 있다.
- 예를들면 Interaction 과 InteractionMetadata를 위한 writer가 있다.
-
-
-]]>
-
-
reader와 동일하게 statementId는 네임스페이스를 가진 구문을 가리킬수 있다.
-
-
매퍼 파일에서 구문은 다음과 같은 방법으로 각각의 레코드를 위해 만들어져있다.
-
-
-
-
-
-
-]]>
-
-
먼저 insertInteractionMetadata가 호출될것이고
- update구문은 jdbc드라이버에 의해(keyProperty 와 keyColumn) 생성된 아이디들을 리턴하기 위해 설정되었다.
- InteractionMetadata 객체가 이 쿼리에 의해 업데이트되면 다음의 쿼리는
- insertInteraction를 통해 상위객체인 Interaction를 작성하기 위해 사용될수 있다.
-
-
방금 언급한 내용에 관련하여 JDBC드라이버가 똑같이 동작하지 않을수 있다.
- 이 글을 쓰는 시점에 H2 드라이버 1.3.168버전(org.h2.jdbc.JdbcStatement#getGeneratedKeys를 보라)만 배치모드에서 마지막 인덱스를 리턴한다.
- 반면에 MySQL 드라이버는 기대한 것과 동일하게 동작하고 모든 아이디를 리턴한다.
일반적인 마이바티스 스프링 사용법에서는, SqlSessionFactoryBean이나 관련된 SqlSessionFactory를 직접 사용할 필요가 없다.
- 대신 세션 팩토리가 MapperFactoryBean나 SqlSessionDaoSupport를 확장하는 다른 DAO에 주입될것이다.
-
-
-
-
-
SqlSessionFactory는 JDBC DataSource의 필수 프로퍼티가 필요하다.
- 어떤 DataSource라도 상관없고 다른 스프링 데이터베이스 연결처럼 설정되어야만 한다.
-
-
하나의 공통적인 프로퍼티는 마이바티스 XML설정파일의 위치를 지정하기 위해 사용되는 configLocation이다.
- 이 프로퍼티를 설정하는 것은 디폴트 설정을 가진 마이바티스 설정을 변경해야 할 경우 뿐이다.
- 대개는 <settings>과 <typeAliases> 섹션을 변경하는 경우이다.
-
-
설정파일이 마이바티스 설정을 완전히 다룰 필요는 없다.
- 어떤 환경, 어떤 데이터소스 그리고 마이바티스 트랜잭션 관리자가 무시될수도 있다.
- SqlSessionFactoryBean 는 필요에 따라 이 값들을 설정하여 자체적인 MyBatis Environment 를 만든다.
-
-
설정파일이 필요한 다른 이유는 마이바티스 XML파일이 매퍼 클래스와 동일한 클래스패스에 있지 않은 경우이다.
- 이 설정을 사용하면 두가지 옵션이 있다.
- 첫번째는 마이바티스 설정파일에 <mappers> 섹션을 사용해서 XML파일의 클래스패스를 지정하는 것이다.
- 두번째는 팩토리 빈의 mapperLocations 프로퍼티를 사용하는 것이다.
-
-
mapperLocations 프로퍼티는 매퍼에 관련된 자원의 위치를 나열한다.
- 이 프로퍼티는 마이바티스의 XML매퍼 파일들의 위치를 지정하기 위해 사용될 수 있다.
- 디렉터리 아래 모든 파일을 로드하기 위해 앤트(Ant) 스타일의 패턴을 사용할수도 있고 가장 상위 위치를 지정하는 것으로 재귀적으로 하위 경로를 찾도록 할수도 있다.
- 예를 들어보면 다음과 같다.
-
-
-
-
-]]>
-
-
이 설정은 sample.config.mappers 패키지 아래와 그 하위 패키지를 모두 검색해서 마이바티스 매퍼 XML파일을 모두 로드할 것이다.
-
-
컨테이너 관리 트랜잭션을 사용하는 환경에서 필요한 하나의 프로퍼티는 transactionFactoryClass 이다.
- 이에 관련해서는 트랜잭션을 다루는 장에서 볼수 있다.
-
-
- 만약 multi-db 기능을 사용한다면 다음과 같이 databaseIdProvider 속성을 설정해야 한다.
-
마이바티스를 스프링과 함께 사용하려면 스프링의 애플리케이션 컨텍스트에 적어도 두개를 정의해줄 필요가 있다.
- 두가지는 SqlSessionFactory와 한개 이상의 매퍼 인터페이스이다.
-
-
마이바티스 스프링 연동모듈에서, SqlSessionFactoryBean은 SqlSessionFactory를 만들기 위해 사용된다.
- 팩토리 빈을 설정하기 위해, 스프링 설정파일에 다음 설정을 추가하자.
-
-
-
-
-]]>
-
-
-
-
SqlSessionFactory는 DataSource를 필요로 하는 것을 알아둘 필요가 있다.
- 어떤 DataSource도 상관없지만 다른 스프링의 데이터베이스 연결과 동일하게 설정되어야 한다.
-
-
매퍼 인터페이스가 다음처럼 정의되었다고 가정해보자.
-
-
-
UserMapper인터페이스는 다음처럼 MapperFactoryBean을 사용해서 스프링에 추가된다.
-
-
-
-]]>
-
-
매퍼는 반드시 구현체 클래스가 아닌 인터페이스로 정의되어야 한다.
- 예를들어, 애노테이션이 SQL을 명시하기 위해 사용되지만 마이바티스 매퍼 XML파일 또한 사용될 수 있다.
-
-
한번만 설정하면, 다른 스프링 빈에 주입하는 같은 방법으로 비즈니스/서비스 객체에 매퍼를 직접 주입할 수 있다.
- MapperFactoryBean은 SqlSession을 생성하고 닫는 작업을 잘 다룬다.
- 실행중인 스프링 트랜잭션이 있다면, 트랜잭션이 완료되는 시점에 커밋이나 롤백이 될 것이다.
- 마지막으로 예외가 발생하면 스프링의 DataAccessException예외가 발생한다.
마이바티스 스프링 연동모듈은 마이바티스와 스프링을 편하고 간단하게 연동한다.
- 이 모듈은 마이바티스로 하여금 스프링 트랜잭션에 쉽게 연동되도록 처리한다.
- 게다가 마이바티스 매퍼와 SqlSession을 다루고 다른 빈에 주입시켜준다.
- 마이바티스 예외를 스프링의 DataAccessException로 변환하기도 하고 마이바티스, 스프링 또는 마이바티스 스프링 연동모듈에 의존성을 없애기도 한다.
-
-
-
-
스프링 2.x은 아이바티스 2.x만을 지원한다.
- 스프링 3.x에서 마이바티스 3.x를 지원하기 위한 시도가 진행중이다.
- (스프링의 이슈관리 시스템인 이슈 를 보라.)
- 불행하게도 스프링 3의 개발이 마이바티스 3.0의 정식릴리즈전에 개발이 완료되었다.
- 그래서 스프링팀은 릴리즈가 안된 마이바티스 코드를 함께 릴리즈하는 것을 원하지 않았고 실제적인 스프링 지원을 기다릴수밖에 없었다.
- 스프링의 마이바티스 지원에 대한 관심으로 인해,
- 마이바티스 커뮤니티는 재결합하는 형태로 결정을 내고 대신 마이바티스의 하위 프로젝트 형태로 스프링 연동 프로젝트를 추가한다.
-
-
-
-
마이바티스 스프링 연동을 시작하기 전에, 마이바티스와 스프링의 용어를 맞추는 일이 굉장히 중요했다.
- 이 문서는 배경지식이나 기본적인 셋업방법 그리고 마이바티스와 스프링의 설정에 대한 튜토리얼등은 제공하지 않는다.
-
- MyBatis-Spring requires following versions:
-
-
-
-
-
- MyBatis-Spring
-
-
- MyBatis
-
-
- Spring Framework
-
-
- Spring Batch
-
-
- Java
-
-
-
-
-
-
- 2.0
-
-
- 3.5+
-
-
- 5.0+
-
-
- 4.0+
-
-
- Java 8+
-
-
-
-
- 1.3
-
-
- 3.4+
-
-
- 3.2.2+
-
-
- 2.1+
-
-
- Java 6+
-
-
-
-
-
-
-
-
이 프로젝트가 실제로 만들어지게 도와준 모든 특별한 분들에게 정말 감사한다.
- 알파벳 순서로 보면, 코딩및 테스트 그리고 문서화를 담당했던 Eduardo Macarron, Hunter Presnall, Putthiphong Boonphong;
- 그외 다양한 프로젝트 기여자인 Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan, Tomas Pinos;
- 그리고 마이바티스에 하위 프로젝트로 가져올수 있도록 많은 것을 찾아준 Simone Tripodi 에게 감사한다. ;)
- 이들이 없었다면 이 프로젝트는 존재하지 않았을 것이다.
-
-
-
-
만약에 어떤 방법으로든 이 문서의 취약점이 발견되거나 기능에 대한 문서화가 빠진 부분이 보인다면,
- 가장 좋은 방법은 먼저 공부해서 자신만의 문서를 작성하는 것이다.
-
-
이 문서의 원본은 xdoc포맷이며 프로젝트의 Git에서 찾을 수 있다.
- repository 를 fork 하고, 업데이트하고 pull request 를 보내주십시오.
-
SqlSessionDaoSupport 나 SqlSessionTemplate 를 직접적으로 사용하는 데이터 접근 객체(DAO)를 생성하기 보다,
- 마이바티스 스프링 연동모듈은 다른 빈에 직접 주입할 수 있는 쓰레드에 안전한 매퍼를 생성할 수 있다.
-
-
-
-]]>
-
-
한번 주입하고나면 매퍼는 애플리케이션 로직에서 사용할수 있는 준비가 된다.
-
-
이 코드를 보면 SqlSession이나 마이바티스 객체가 보이지 않는다.
- 게다가 세션을 생성하거나 열고 닫을필요도 없어보인다.
- 마이바티스 스프링 연동모듈이 알아서 처리할 것이다.
-
-
-
매퍼를 등록하는 방법은 기존의 전통적인 XML설정법을 사용하거나 새로운 3.0 이후의 자바설정(일명 @Configuration)을 사용하느냐에 따라 다르다.
-
-
XML설정 사용
-
-
매퍼는 다음처럼 XML설정파일에 MapperFactoryBean을 두는 것으로 스프링에 등록된다.
-
-
-
-]]>
-
-
UserMapper가 매퍼 인터페이스와 같은 경로의 클래스패스에 마이바티스 XML매퍼 파일을 가지고 있다면 MapperFactoryBean이 자동으로 파싱할것이다.
- 매퍼 XML파일을 다른 클래스패스에 두는게 아니라면 마이바티스 설정파일에 매퍼를 지정할 필요가 없다.
- 좀더 세부적인 정보는 SqlSessionFactoryBean의 configLocation 프로퍼티를 살펴보자.
-
-
MapperFactoryBean은 SqlSessionFactory 나 SqlSessionTemplate가 필요하다.
- sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 셋팅하면 된다.
- 둘다 셋팅하면 SqlSessionFactory가 무시된다.
- 세션 팩토리 셋은 SqlSessionTemplate이 필요하고 MapperFactoryBean는 팩토리를 사용할것이다.
하나씩 매퍼를 모두 등록할 필요가 없다.
- 대신 클래스패스를 지정해서 마이바티스 스프링 연동모듈의 자동스캔기능을 사용할 수 있다.
-
-
자동스캔을 사용하는데는 3가지 방법이 있다.
-
-
<mybatis:scan/> 엘리먼트 사용
-
@MapperScan 애노테이션 사용
-
스프링 XML파일을 사용해서 MapperScannerConfigurer를 등록
-
-
-
<mybatis:scan/> 와 @MapperScan 모두 마이바티스 스프링 연동모듈 1.2.0에서 추가된 기능이다.
- @MapperScan 은 스프링 버전이 3.1이상이어야 한다.
-
-
- Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
- that control lazy initialization enabled/disabled of mapper bean.
- The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
- The default of this option is false (= not use lazy initialization).
- If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
-
-
- IMPORTANT If use the lazy initialization feature,
- the developer need to understand following limitations. If any of following conditions are matches,
- usually the lazy initialization feature cannot use on your application.
-
-
-
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
-
When includes to the fragment of other mapper using ]]>
-
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
-
When refers to the result mapping of other mapper using ]]>(@ResultMap)
-
-
-
- NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
-
-
-
-
-
- Since 2.0.6, the develop become can specified scope of mapper using mapper scanning feature option(default-scope)
- and scope annotation(@Scope, @RefreshScope, etc ...).
- The motivation for adding this option is supporting the refresh scope provided by the Spring Cloud.
- The default of this option is empty (= equiv to specify the singleton scope).
- The default-scope apply to the mapper bean(MapperFactoryBean) when scope of scanned bean definition
- is singleton(default scope) and create a scoped proxy bean for scanned mapper when final scope is not singleton.
-
-
-
<mybatis:scan/>
-
-
<mybatis:scan/> XML엘리먼트는 스프링에서 제공하는 <context:component-scan/> 엘리먼트와 매우 유사한 방법으로 매퍼를 검색할 것이다.
-
-
샘플 XML설정을 아래에서 볼수 있다.
-
-
-
-
-
-
-
-]]>
-
-
base-package 속성은 매퍼 인터페이스 파일이 있는 가장 상위 패키지를 지정하면 된다.
- 세미콜론이나 콤마를 구분자로 사용해서 한개 이상의 패키지를 셋팅할 수 있다.
- 매퍼는 지정된 패키지에서 재귀적으로 하위 패키지를 모두 검색할 것이다.
-
-
<mybatis:scan/>이 자동으로 주입할 수 있는 MapperFactoryBean를 생성하기 때문에
- SqlSessionFactory 나 SqlSessionTemplate 를 명시할 필요가 없다.
- 하지만 한개 이상의 DataSource를 사용한다면 자동주입이 생각한데로 동작하지 않을수도 있다.
- 이 경우 사용할 빈 이름을 지정하기 위해 factory-ref 나 template-ref 속성을 사용할수 있다.
-
-
<mybatis:scan/>은 마커(marker) 인터페이스나 애노테이션을 명시해서 생성되는 매퍼를 필터링할수도 있다.
- annotation 프로퍼티는 검색할 애노테이션을 지정한다.
- marker-interface 프로퍼티는 검색할 상위 인터페이스를 지정한다.
- 이 두개의 프로퍼티를 모두 지정하면, 매퍼는 두 조건을 모두 만족하는 인터페이스만을 추가한다.
- 디폴트로 이 두가지 프로퍼티는 모두 null이다.
- 그래서 base-package프로퍼티에 설정된 패키지 아래 모든 인터페이스가 매퍼로 로드될 것이다.
-
-
발견된 매퍼는 자동검색된 컴포넌트를 위한 스프링의 디폴트 명명규칙 전략(see the Spring reference document(Core Technologies -Naming autodetected components-))을 사용해서 빈이름이 명명된다.
- 빈 이름을 정하는 애노테이션이 없다면 매퍼의 이름에서 첫글자를 소문자로 변환한 형태로 빈 이름을 사용할 것이다.
- @Component 나 JSR-330의 @Named 애노테이션이 있다면 애노테이션에 정의한 이름을 그대로 사용할 것이다.
- annotation 프로퍼티를 org.springframework.stereotype.Component,
- javax.inject.Named(자바SE 1.6을 사용한다면) 또는 개발자가 스스로 작성한 애노테이션으로 셋팅할 수 있다.
- 그러면 애노테이션은 마커와 이름을 제공하는 역할로 동작할 것이다.
-
-
- 중요<context:component-scan/> 가 매퍼를 검색해서 등록을 하지 못할수도 있다.
- 매퍼는 인터페이스고 스프링에 빈으로 등록하기 위해서는 각각의 인터페이스를 찾기 위해 스캐너가 MapperFactoryBean 를 생성하는 방법을 알아야만 한다.
-
-
@MapperScan
-
-
@Configuration 라고 불리는 스프링의 자바설정을 사용한다면 <mybatis:scan/>보다는
- @MapperScan를 사용하길 선호할것이다.
-
-
@MapperScan 애노테이션은 다음처럼 사용된다.
-
-
-
-
애노테이션은 앞서 본 <mybatis:scan/> 에서 설명하는 것과 동일하게 동작한다.
- markerInterface 와 annotationClass 프로퍼티를 사용해서 마커 인터페이스와 애노테이션 클래스를 명시하게 한다.
- sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 사용해서
- SqlSessionFactory 나 SqlSessionTemplate을 제공할 수도 있다.
-
-
- NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
-
-
-
MapperScannerConfigurer
-
-
MapperScannerConfigurer는 평범한 빈처럼 XML애플리케이션 컨텍스트에 포함된 BeanDefinitionRegistryPostProcessor 이다.
- MapperScannerConfigurer를 셋업하기 위해 다음의 스프링 설정을 추가하자.
-
-
-]]>
-
-
sqlSessionFactory 나 sqlSessionTemplate를 지정할 필요가 있다면 빈참조가 아닌 빈이름이 필요하다.
- value 프로퍼티는 빈 이름을 지정하고 ref 는 빈 참조를 지정하기 때문에 value 프로퍼티를 사용하자.
- ]]>
-
-
중요sqlSessionFactoryBean 과 sqlSessionTemplateBean 프로퍼티는
- 마이바티스 스프링 연동모듈 1.0.2 버전 이상에서만 사용이 가능하다. 하지만 MapperScannerConfigurer는 잦은 에러를 발생시키는
- PropertyPlaceholderConfigurer보다 앞서 실행되기 때문에 이 프로퍼티들은 사용하지 말길 바란다(deprecated).
- 대신 새롭게 추가된 프로퍼티인 sqlSessionFactoryBeanName 과 sqlSessionTemplateBeanName 를 사용하도록 권한다.
- 샘플 코드는 트랜잭션 서비스가 data access layer 에서 도메인 개체를 가져 오는 일반적인 디자인을 보여준다.
-
-
- 다음 FooService.java 는 서비스처럼 작동한다.
-
-
-
- 이것은 트랜잭션 빈이다. 따라서 어떤 메서드든 실행이 되면 트랜잭션이 시작되고 예외가 발생하지 않았을 때 커밋된다.
- 트랜잭션은 @Transactional annotation 을 통해 설정할 수 있다.
- 이것은 필수가 아니다. Spring이 제공하는 다른 방법을 사용하여 트랜잭션을 구분할 수 있다.
-
-
- 이 서비스는 MyBatis로 이루어진 DAO layer 를 호출한다.
- 이 layer는 런타임시 MyBatis에 의해 작성되고 Spring에 의해 서비스에 주입되는 동적 프록시와 함께 사용되는 UserMapper.java 인터페이스로 구성된다.
-
-
-
- 단순함을 위해서 DAO가 인터페이스와 그 구현체로 만들어진 DAO 시나리오를 위해 UserMapper.java 인터페이스를 사용했지만,
- 이 경우 대신 UserDao.java라는 인터페이스를 사용하는 것이 더 적절하다.
-
-
- 매퍼 인터페이스를 찾고 Spring에 등록하고 서비스 빈에 주입하는 여러 가지 방법을 살펴본다.
-
-
-
시나리오
-
-
-
샘플 테스트
-
설명
-
-
-
-
-
- SampleMapperTest.java
-
-
- UserMapper 구현체를 동적으로 빌드 할 MapperFactoryBean에 기반한 기본 구성을 보여준다.
-
-
-
-
- SampleScannerTest.java
-
-
- MapperScannerConfigurer 를 사용하여 어떻게 프로젝트의 모든 매퍼들을 자동으로 검색되도록 하는 방법을 보여준다.
-
-
-
-
- SampleSqlSessionTest.java
-
-
- Spring에서 관리하는 SqlSession을 사용하여 DAO를 코딩하고 자체적인 구현체인 UserDaoImpl.java 를 제공하는 방법을 보여준다.
-
-
-
-
- SampleEnableTest
-
-
- 스프링의 @Configuration과 @MapperScann annotation을 함께 사용하여 매퍼를 자동으로 검색하는 방법을 보여준다.
-
-
-
-
- SampleNamespaceTest
-
-
- 커스텀 MyBatis XML 네임스페이스를 사용하는 방법을 보여준다.
-
-
-
-
- SampleJavaConfigTest.java
-
-
- 스프링의 @Configuration을 사용하여 MyBatis 빈들을 수동적으로 생성하는 방법을 보여준다.
-
-
-
-
- SampleJobJavaConfigTest.java
-
-
- Java Configuration을 이용하여 Spring Batch에서 어떻게 ItemReader과 ItemWriter를 사용하는지 보여준다.
-
-
-
-
- SampleJobXmlConfigTest.java
-
-
- XML Configuration을 이용하여 Spring Batch에서 어떻게 ItemReader과 ItemWriter를 사용하는지 보여준다.
-
-
-
-
-
- MyBatis-Spring이 실제로 어떻게 다르게 작동하는지 보려면 applicationContext.xml 파일을 살펴보십시오.
-
마이바티스에서는 SqlSession를 생성하기 위해 SqlSessionFactory를 사용한다.
- 세션을 한번 생성하면 매핑구문을 실행하거나 커밋 또는 롤백을 하기 위해 세션을 사용할수 있다.
- 마지막으로 더 이상 필요하지 않은 상태가 되면 세션을 닫는다.
- 마이바티스 스프링 연동모듈을 사용하면 SqlSessionFactory를 직접 사용할 필요가 없다.
- 왜냐하면, 스프링 트랜잭션 설정에 따라 자동으로 커밋 혹은 롤백을 수행하고 닫혀지는, 쓰레드에 안전한 SqlSession 개체가 스프링 빈에 주입될 수 있기 때문이다.
-
-
-
SqlSessionTemplate은 마이바티스 스프링 연동모듈의 핵심이다.
- SqlSessionTemplate은 SqlSession을 구현하고 코드에서 SqlSession를 대체하는 역할을 한다.
- SqlSessionTemplate 은 쓰레드에 안전하고 여러개의 DAO나 매퍼에서 공유할수 있다.
-
-
getMapper()에 의해 리턴된 매퍼가 가진 메서드를 포함해서 SQL을 처리하는 마이바티스 메서드를 호출할때
- SqlSessionTemplate은 SqlSession이 현재의 스프링 트랜잭션에서 사용될수 있도록 보장한다.
- 추가적으로 SqlSessionTemplate은 필요한 시점에 세션을 닫고, 커밋하거나 롤백하는 것을 포함한 세션의 생명주기를 관리한다.
- 또한 마이바티스 예외를 스프링의 DataAccessException로 변환하는 작업또한 처리한다.
-
-
SqlSessionTemplate은 마이바티스의 디폴트 구현체인 DefaultSqlSession 대신 항상 사용된다.
- 왜냐하면 템플릿은 스프링 트랜잭션의 일부처럼 사용될 수 있고 여러개 주입된 매퍼 클래스에 의해 사용되도록 쓰레드에 안전하다.
- 동일한 애플리케이션에서 두개의 클래스간의 전환은 데이터 무결성 이슈를 야기할수 있다.
-
-
SqlSessionTemplate은 생성자 인자로 SqlSessionFactory를 사용해서 생성될 수 있다.
-
-
-]]>
-
-
-
-
이 빈은 DAO빈에 직접 주입될 수 있다. 다음처럼 빈 설정에서 SqlSession 프로퍼티를 설정하면 된다.
-
-
그리고 다음처럼 SqlSessionTemplate 를 주입하자.
-
-
-]]>
-
-
SqlSessionTemplate은 인자로 ExecutorType를 가지는 생성자를 가지고 있다.
- 이 인자는 예를들면 스프링 설정 XML을 다음처럼 설정해서 배치형태의 SqlSession를 만들수도 있다.
-
-
-
-]]>
-
-
-
-
DAO의 코드를 다음처럼 작성했다면 모든 구문은 배치형태로 실행이 될 것이다.
- users) {
- for (User user : users) {
- sqlSession.insert("org.mybatis.spring.sample.mapper.UserMapper.insertUser", user);
- }
-}]]>
-
-
이러한 설정형태는 SqlSessionFactory의 디폴트 형태가 아닌 다른형태로 메서드를 실행해야 할때만 사용할 필요가 있다.
-
-
이러한 형태에 대해 굳이 경로를 하자면 메서드를 호출할때 ExecutorType이 다르면 이미 시작된 트랜잭션을 사용하지 못할것이다.
- 다른 실행자(executor) 타입을 사용할때는 SqlSessionTemplate의 메서드를 구분된 트랜잭션(PROPAGATION_REQUIRES_NEW를 사용하는)이나 트랜잭션 외부에서 호출하는지 확실히해야 한다.
-
-
-
-
SqlSessionDaoSupport는 SqlSession을 제공하는 추상클래스이다.
- getSqlSession()메서드를 호출해서 다음처럼 SQL을 처리하는 마이바티스 메서드를 호출하기 위해 사용할 SqlSessionTemplate을 얻을 수 있다.
-
-
대개 MapperFactoryBean은 추가적인 코드가 필요없기 때문에 이 클래스를 선호한다.
- 하지만 DAO에서 마이바티스가 필요하지 않고 구현된 클래스가 필요하지 않을때만 유용하다.
-
-
SqlSessionDaoSupport는 sqlSessionFactory 와 sqlSessionTemplate 프로퍼티를 셋팅할 필요가 있다.
- 두개의 프로퍼티를 모두 셋팅하면 sqlSessionFactory는 무시된다.
-
-
SqlSessionDaoSupport의 하위클래스인 UserDaoImpl가 있다고 하면 스프링에서는 다음처럼 설정될 수 있다.
마이바티스 스프링 연동모듈을 사용하는 중요한 이유중 하나는 마이바티스가 스프링 트랜잭션에 자연스럽게 연동될수 있다는 것이다.
- 마이바티스에 종속되는 새로운 트랜잭션 관리를 만드는 것보다는 마이바티스 스프링 연동모듈이 스프링의 DataSourceTransactionManager과 융합되는 것이 좋다.
-
스프링 트랜잭션 관리자를 한번 설정하면, 대개의 경우처럼 스프링에서 트랜잭션을 설정할 수 있다.
- @Transactional 애노테이션과 AOP스타일의 설정 모두 지원한다.
- 하나의 SqlSession객체가 생성되고 트랜잭션이 동작하는 동안 지속적으로 사용될것이다.
- 세션은 트랜잭션이 완료되면 적절히 커밋이 되거나 롤백될것이다.
-
마이바티스 스프링 연동모듈은 한번 셋업되면 트랜잭션을 투명하게 관리한다.
- DAO클래스에 어떠한 추가적인 코드를 넣을 필요가 없다.
-
-
-
스프링 트랜잭션을 가능하게 하려면, 스프링 설정파일에 DataSourceTransactionManager를 생성하자.
-
-
-]]>
-
-
-
-
명시된 DataSource는 스프링을 사용할때 일반적으로 사용한다면 어떠한 JDBC DataSource도 될수 있다.
- JNDI룩업을 통해 얻어진 DataSource뿐 아니라 커넥션 풀링 기능도 포함한다.
-
트랜잭션 관리자에 명시된 DataSource가 SqlSessionFactoryBean을 생성할때 사용된 것과 반드시 동일한 것이어야 하는 것만 꼭 기억하자.
- 그렇지 않으면 트랜잭션 관리가 제대로 되지 않을것이다.
-
-
-
-
만약에 JEE컨테이너를 사용하고 스프링을 컨테이너 관리 트랜잭션(container managed transactions, CMT)에 두려한다면,
- 스프링은 JtaTransactionManager나 그 하위 클래스로 설정되어야 한다.
- 이러한 설정을 가장 쉽게 하는 방법은 스프링의 트랜잭션 네임스페이스 or JtaTransactionManagerFactoryBean 를 사용하는 것이다.
-
- ]]>
-
-
-
-
이 설정에서, 마이바티스는 CMT와 함께 설정된 스프링 트랜잭션 리소스처럼 동작할 것이다.
- 스프링은 이미 설정된 트랜잭션을 사용해서 SqlSession을 이미 동작중인 트랜잭션에 넣을 것이다.
- 시작된 트랜잭션이 없고 트랜잭션이 필요한 경우라면 스프링은 새로운 컨테이너 관리 트랜잭션을 시작할 것이다.
-
CMT는 사용하지만 스프링 트랜잭션 관리를 원하지 않는다면 어떠한 스프링 트랜잭션 관리자를 설정해서도 안되고
- 마이바티스 ManagedTransactionFactory를 사용하기 위해 SqlSessionFactoryBean를 설정해야만 한다.
-
-
-
-
-
-]]>
-
-
-
-
-
-
-
마이바티스 SqlSession은 트랜잭션을 제어하는 메서드를 제공한다.
- 하지만 마이바티스 스프링 연동모듈은 빈을 스프링이 관리하는 SqlSession이나 스프링이 관리하는 매퍼에 주입한다.
- 이 말은 스프링이 항상 트랜잭션을 관리한다는 뜻이다.
-
스프링이 관리하는 SqlSession에서는 SqlSession.commit(), SqlSession.rollback()
- 또는 SqlSession.close() 메서드를 호출할수가 없다.
- 그럼에도 불구하고 이 메서드들을 사용하면 UnsupportedOperationException 예외가 발생한다.
- 이러한 메서드는 주입된 매퍼 클래스에서는 사용할 수 없다.
-
JDBC연결의 자동커밋 설정을 어떻게 하더라도 스프링 트랜잭션 밖의 SqlSession 데이터 메서드나 매퍼 메서드의 실행은 자동으로 커밋된다.
MyBatis-Spring 연동 모듈을 사용해도 계속해서 MyBatis API를 직접 사용할 수 있다.
- SqlSessionFactoryBean을 사용해서 스프링에서 SqlSessionFactory를 생성하고 팩토리를 사용하면 된다.
-
-
-
이 방법은 신중히 사용하자. 왜냐하면 잘못사용하면 런타임 에러나 데이터 문제등을 야기할수 있기 때문이다.
- API를 직접 사용할때는 다음의 규칙들에 유의해야 한다.
-
-
-
스프링 트랜잭션에 속하지 않고 별도의 트랜잭션에서 동작한다.
-
-
-
SqlSession이 스프링 트랜잭션 관리자가 사용하는 DataSource를 사용하고
- 이미 트랜잭션이 동작하고 있다면 이 코드는 예외를 발생시킬 것이다.
-
-
-
마이바티스의 DefaultSqlSession은 쓰레드에 안전하지 않다.
- 빈에 이 객체를 주입하면 아마도 에러를 발생시킬 수 있다.
-
-
-
DefaultSqlSession을 사용해서 생성한 매퍼 또한 쓰레드에 안전하지 않다.
- 이렇게 만든 매퍼를 빈에 주입하면 에러를 발생시킬 수 있다.
-
-
-
SqlSession은 항상 마지막에 close() 메서드를 호출해야 한다.
-
-
-
-
-
diff --git a/src/site/markdown/README.md b/src/site/markdown/README.md
new file mode 100644
index 0000000000..74036dbd21
--- /dev/null
+++ b/src/site/markdown/README.md
@@ -0,0 +1,18 @@
+# Table of contents
+
+This page is for rendering index on GitHub.
+
+> **NOTE:**
+>
+> Since the link destination is specified on the assumption that it is converted to html with maven-site-plugin, there is an anchor that is broken in the rendering on GitHub.
+
+* [Introduction](./index.md)
+* [Getting Started](./getting-started.md)
+* [SqlSessionFactoryBean](./factorybean.md)
+* [Transactions](./transactions.md)
+* [Using an SqlSession](./sqlsession.md)
+* [Injecting Mappers](./mappers.md)
+* [Spring Boot](./boot.md)
+* [Using the MyBatis API](./using-api.md)
+* [Spring Batch](./batch.md)
+* [Sample Code](./sample.md)
diff --git a/src/site/markdown/batch.md b/src/site/markdown/batch.md
new file mode 100644
index 0000000000..a6ad50418c
--- /dev/null
+++ b/src/site/markdown/batch.md
@@ -0,0 +1,359 @@
+
+# Spring Batch
+
+As of version 1.1.0 MyBatis-Spring provides three beans for building Spring Batch applications: the `MyBatisPagingItemReader`, the `MyBatisCursorItemReader` and the `MyBatisBatchItemWriter`.
+Also, As of version 2.0.0 provides three builder classes for supporting the Java Configuration: the `MyBatisPagingItemReaderBuilder`, the `MyBatisCursorItemReaderBuilder` and the `MyBatisBatchItemWriterBuilder`.
+
+NOTE
+This is about [Spring Batch](http://static.springsource.org/spring-batch/) and not about MyBatis batch SqlSessions. For information about batch sessions go to section [Using an SqlSession](sqlsession.html).
+
+## MyBatisPagingItemReader
+
+This bean is an `ItemReader` that reads records from a database in a paging fashion.
+
+It executes the query specified as the `setQueryId` property to retrieve requested data.
+The query is executed using paged requests of a size specified in `setPageSize` property.
+Additional pages are requested when needed as `read()` method is called, returning an object corresponding to current position.
+
+Some standard query parameters are provided by the reader and the SQL in the named query must use some or all of these parameters (depending on the SQL variant) to construct a result set of the required size.
+The parameters are:
+
+* `_page`: the page number to be read (starting at 0)
+* `_pagesize`: the size of the pages, i.e. the number of rows to return
+* `_skiprows`: the product of `_page` and `_pagesize`
+
+And they could be mapped as the follow in a select statement:
+
+```xml
+
+```
+
+Follows below a sample configuration snippet:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisPagingItemReader reader() {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+**Explaining a more complex example:**
+
+```xml
+
+```
+```xml
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @StepScope
+ @Bean
+ public MyBatisPagingItemReader dateBasedCriteriaReader(
+ @Value("#{@datesParameters}") Map datesParameters) throws Exception {
+ return new MyBatisPagingItemReaderBuilder()
+ .sqlSessionFactory(batchReadingSessionFactory())
+ .queryId("com.my.name.space.batch.ExampleMapper.queryUserInteractionsOnSpecificTimeSlot")
+ .parameterValues(datesParameters)
+ .pageSize(200)
+ .build();
+ }
+
+ @StepScope
+ @Bean
+ public Map datesParameters(
+ @Value("#{jobExecutionContext['EXTRACTION_START_DATE']}") LocalDate yesterday,
+ @Value("#{jobExecutionContext['TODAY_DATE']}") LocalDate today,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_MONTH_DATE']}") LocalDate firstDayOfTheMonth,
+ @Value("#{jobExecutionContext['FIRST_DAY_OF_THE_PREVIOUS_MONTH_DATE']}") LocalDate firstDayOfThePreviousMonth) {
+ Map map = new HashMap<>();
+ map.put("yesterday", yesterday);
+ map.put("today", today);
+ map.put("first_day_of_the_month", firstDayOfTheMonth);
+ map.put("first_day_of_the_previous_month", firstDayOfThePreviousMonth);
+ return map;
+ }
+}
+```
+
+The previous example makes use of a few different things:
+
+* `sqlSessionFactory`: You can specify your own sessionFactory to the reader, it might be useful if you want to read from several databases.
+
+* `queryId`: If the base code have several tables or databases to read from, and that you have different queries, it might be interesting to use different mapper files with different namespaces.
+ so when referring to the query, don't forget about the namespace of the mapper file.
+
+* `parameterValues`: You can pass additional parameters via this map, the example above uses a map that is build by spring using a SpEL expression taking values from the `jobExecutionContext`.
+ The keys of the map will be used by MyBatis in the mapper file (ex: *yesterday* could be used as `#{yesterday,jdbcType=TIMESTAMP}`).
+ Note that the map and the reader are both built in the `step` scope in order to be able to use the Spring EL expression with the `jobExecutionContext`.
+ Also if MyBatis type handlers are correctly configured you can pass custom instances like the parameters of this map that are JodaTime dates.
+
+* `pageSize`: If the batch flow is configured with chunk size, it is relevant to pass this information to the reader as well, which is done via this property.
+
+## MyBatisCursorItemReader
+
+This bean is an `ItemReader` that reads records from a database using a cursor.
+
+NOTE
+To use this bean you need at least MyBatis 3.4.0 or a newer version.
+
+It executes the query specified as the `setQueryId` property to retrieve requested data by using the method `selectCursor()`.
+Each time a `read()` method is called it will return the next element of the cursor until no more elements are left.
+
+The reader will use a separate connection so the select statement does no participate in any transactions created as part of the step processing.
+
+When using the cursor you can just execute a regular query:
+
+```xml
+
+```
+
+Follows below a sample configuration snippet:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisCursorItemReader reader() {
+ return new MyBatisCursorItemReaderBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .queryId("com.my.name.space.batch.EmployeeMapper.getEmployee")
+ .build();
+ }
+}
+```
+
+## MyBatisBatchItemWriter
+
+It is an `ItemWriter` that uses the batching features from `SqlSessionTemplate` to execute a batch of statements for all items provided.
+The `SqlSessionFactory` needs to be configured with a `BATCH` executor.
+
+When `write()` is called it executes the mapped statement indicated in the property `statementId`. It is expected that `write()` is called inside a transaction.
+
+Follows below a sample configuration snippet:
+
+```xml
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("com.my.name.space.batch.EmployeeMapper.updateEmployee")
+ .build();
+ }
+}
+```
+
+**Converting a item that read using ItemReader to an any parameter object:**
+
+By default behavior, the `MyBatisBatchItemWriter` passes a item that read using `ItemReader` (or convert by `ItemProcessor`) to the MyBatis(`SqlSession#update()`) as the parameter object.
+If you want to customize a parameter object that passes to the MyBatis, you can realize to use the `itemToParameterConverter` option.
+For example using `itemToParameterConverter` option, you can passes any objects other than the item object to the MyBatis.
+Follows below a sample:
+
+At first, you create a custom converter class (or factory method). The following sample uses a factory method.
+
+```java
+public class ItemToParameterMapConverters {
+ public static Converter> createItemToParameterMapConverter(String operationBy, LocalDateTime operationAt) {
+ return item -> {
+ Map parameter = new HashMap<>();
+ parameter.put("item", item);
+ parameter.put("operationBy", operationBy);
+ parameter.put("operationAt", operationAt);
+ return parameter;
+ };
+ }
+}
+```
+
+At next, you write a sql mapping.
+
+```xml
+
+```
+
+At last, you configure the MyBatisBatchItemWriter.
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public MyBatisBatchItemWriter writer() throws Exception {
+ return new MyBatisBatchItemWriterBuilder()
+ .sqlSessionFactory(sqlSessionFactory())
+ .statementId("org.mybatis.spring.sample.mapper.PersonMapper.createPerson")
+ .itemToParameterConverter(createItemToParameterMapConverter("batch_java_config_user", LocalDateTime.now()))
+ .build();
+ }
+}
+```
+
+```xml
+
+
+
+
+
+
+
+
+
+
+```
+
+**Writing to different tables using composite writers (with some caveats):**
+
+This technique can only be used with MyBatis 3.2+, as there was an [issue](http://code.google.com/p/mybatis/issues/detail?id=741) in previous versions that made the writer misbehave.
+
+If the batch needs to write complex data, like records with associations, or even to different databases, then it is possible to work around the fact that insert statements only insert in one table.
+In order to make it happen the batch have to prepare the *Item* to be written by the writer.
+However depending on the constraints, opportunities or insight on the processed data it might be interesting to use the following technique.
+The following trick can work on items with simple associations or just with unrelated tables.
+
+In a processor craft the Spring Batch Item in such way it will *hold* all the different records.
+Suppose for each Item there is an *Interaction* that have one association *InteractionMetadata*,
+and two non associated rows *VisitorInteraction* and *CustomerInteraction*, the holder object will look like:
+
+```java
+public class InteractionRecordToWriteInMultipleTables {
+ private final VisitorInteraction visitorInteraction;
+ private final CustomerInteraction customerInteraction;
+ private final Interaction interaction;
+ // ...
+}
+```
+```java
+public class Interaction {
+ private final InteractionMetadata interactionMetadata;
+}
+```
+
+Then in the spring configuration there will be a `CompositeItemWriter` that will use delegate writers specifically configured for each kind of records.
+Note that as the *InteractionMetadata* is an association in the example it will need to be written first so that Interaction can have the updated key.
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+```java
+@Configuration
+public class BatchAppConfig {
+ @Bean
+ public CompositeItemWriter> interactionsItemWriter() {
+ CompositeItemWriter compositeItemWriter = new CompositeItemWriter();
+ List> writers = new ArrayList<>(4);
+ writers.add(visitorInteractionsWriter());
+ writers.add(customerInteractionsWriter());
+ writers.add(interactionMetadataWriter());
+ writers.add(interactionWriter());
+ compositeItemWriter.setDelegates(writers);
+ return compositeItemWriter;
+ }
+}
+```
+
+Then each delegate writer will be configured as needed; for example for *Interaction* and *InteractionMetadata*:
+
+```xml
+
+```
+```xml
+
+```
+
+Same as the reader the `statementId` can refer to the statement with the prefixed namespace.
+
+Now in the mapper file the statement have to be crafted for each kind of records in the following way:
+
+```xml
+
+
+
+```
+```xml
+
+
+
+```
+
+What's happening is that first the `insertInteractionMetadata` will be called, and the update statement is configured to return the ids created by the jdbc driver (`keyProperty` and `keyColumn`).
+As the `InteractionMetadata` object were updated by this query the next query can be used to write the parent object `Interaction` via `insertInteraction`.
+
+***However note that JDBC drivers don't behave the same in this regard. At the time of this writing the H2 driver 1.3.168 will only return the latest index even in BATCH mode (see `org.h2.jdbc.JdbcStatement#getGeneratedKeys`),
+while the MySQL JDBC driver will behave as expected and return all the IDs.***
diff --git a/src/site/markdown/boot.md b/src/site/markdown/boot.md
new file mode 100644
index 0000000000..678db5d753
--- /dev/null
+++ b/src/site/markdown/boot.md
@@ -0,0 +1,4 @@
+
+# Using Spring Boot
+
+Please see the [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) sub project docs for details.
diff --git a/src/site/markdown/factorybean.md b/src/site/markdown/factorybean.md
new file mode 100644
index 0000000000..cf403649f8
--- /dev/null
+++ b/src/site/markdown/factorybean.md
@@ -0,0 +1,100 @@
+
+# SqlSessionFactoryBean
+
+In base MyBatis, the `SqlSessionFactory` is built using `SqlSessionFactoryBuilder`. In MyBatis-Spring, `SqlSessionFactoryBean` is used instead.
+
+## Setup
+
+To create the factory bean, put the following in the Spring XML configuration file:
+
+```xml
+
+
+
+```
+Note that `SqlSessionFactoryBean` implements Spring's `FactoryBean` interface see [the Spring documentation(Core Technologies -Customizing instantiation logic with a FactoryBean-)](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-extension-factorybean)).
+This means that the bean Spring ultimately creates is **not** the `SqlSessionFactoryBean` itself, but what the factory returns as a result of the `getObject()` call on the factory.
+In this case, Spring will build an `SqlSessionFactory` for you at application startup and store it with the name `sqlSessionFactory`.
+In Java, the equivalent code would be:
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+In normal MyBatis-Spring usage, you will not need to use `SqlSessionFactoryBean` or the corresponding `SqlSessionFactory` directly.
+Instead, the session factory will be injected into `MapperFactoryBean`s or other DAOs that extend `SqlSessionDaoSupport`.
+
+## Properties
+
+`SqlSessionFactory` has a single required property, the JDBC `DataSource`. This can be any `DataSource` and should be configured just like any other Spring database connection.
+
+One common property is `configLocation` which is used to specify the location of the MyBatis XML configuration file.
+One case where this is needed is if the base MyBatis configuration needs to be changed. Usually this will be `` or `` sections.
+
+Note that this config file does **not** need to be a complete MyBatis config. Specifically, any environments, data sources and MyBatis transaction managers will be **ignored**.
+`SqlSessionFactoryBean` creates its own, custom MyBatis `Environment` with these values set as required.
+
+Another reason to require a config file is if the MyBatis mapper XML files are not in the same classpath location as the mapper classes. With this configuration, there are two options.
+This first is to manually specify the classpath of the XML files using a `` section in the MyBatis config file. A second option is to use the `mapperLocations` property of the factory bean.
+
+The `mapperLocations` property takes a list of resource locations. This property can be used to specify the location of MyBatis XML mapper files.
+The value can contain Ant-style patterns to load all files in a directory or to recursively search all paths from a base location.
+
+For example:
+
+```xml
+
+
+
+
+```
+
+This will load all the MyBatis mapper XML files in the `sample.config.mappers` package and its sub-packages from the classpath.
+
+One property that may be required in an environment with container managed transactions is `transactionFactoryClass`. Please see the relevant section in the Transactions chapter.
+
+In case you are using the multi-db feature you will need to set the `databaseIdProvider` property:
+
+```xml
+
+
+
+ sqlserver
+ db2
+ oracle
+ mysql
+
+
+
+```
+```xml
+
+
+
+
+
+```
+
+NOTE
+Since 1.3.0, `configuration` property has been added. It can be specified a `Configuration` instance directly without MyBatis XML configuration file.
+
+For example:
+
+```xml
+
+
+
+
+
+
+
+
+```
diff --git a/src/site/markdown/getting-started.md b/src/site/markdown/getting-started.md
new file mode 100644
index 0000000000..c33f7f393d
--- /dev/null
+++ b/src/site/markdown/getting-started.md
@@ -0,0 +1,100 @@
+
+# Getting Started
+
+This chapter will show you in a few steps how to install and setup MyBatis-Spring and how to build a simple transactional application.
+
+## Installation
+
+To use the MyBatis-Spring module, you just need to include the `mybatis-spring-${project.version}.jar` file and its dependencies in the classpath.
+
+If you are using Maven just add the following dependency to your pom.xml:
+
+```xml
+
+ org.mybatis
+ mybatis-spring
+ ${project.version}
+
+```
+
+## Quick Setup
+
+To use MyBatis with Spring you need at least two things defined in the Spring application context:
+an `SqlSessionFactory` and at least one mapper interface.
+
+In MyBatis-Spring, an `SqlSessionFactoryBean` is used to create an `SqlSessionFactory`. To configure the factory bean, put the following in the Spring configuration file:
+
+```xml
+
+
+
+```
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public SqlSessionFactory sqlSessionFactory() throws Exception {
+ SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource());
+ return factoryBean.getObject();
+ }
+}
+```
+
+Notice that the `SqlSessionFactory` requires a `DataSource`. This can be any `DataSource` and should be configured just like any other Spring database connection.
+
+Assume you have a mapper interface defined like the following:
+
+```java
+public interface UserMapper {
+ @Select("SELECT * FROM users WHERE id = #{userId}")
+ User getUser(@Param("userId") String userId);
+}
+```
+
+This interface is added to Spring using a `MapperFactoryBean` like the following:
+
+```xml
+
+
+
+
+```
+
+Note that the mapper class specified **must** be an interface, not an actual implementation class. In this example, annotations are used to specify the SQL, but a MyBatis mapper XML file could also be used.
+
+Once configured, you can inject mappers directly into your business/service objects in the same way you inject any other Spring bean.
+The `MapperFactoryBean` handles creating an `SqlSession` as well as closing it.
+If there is a Spring transaction in progress, the session will also be committed or rolled back when the transaction completes.
+Finally, any exceptions will be translated into Spring `DataAccessException`s.
+
+If you use the Java Configuration:
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public UserMapper userMapper() throws Exception {
+ SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory());
+ return sqlSessionTemplate.getMapper(UserMapper.class);
+ }
+}
+```
+
+Calling MyBatis data methods is now only one line of code:
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
new file mode 100644
index 0000000000..c7b577c2ff
--- /dev/null
+++ b/src/site/markdown/index.md
@@ -0,0 +1,54 @@
+
+# Introduction
+
+## What is MyBatis-Spring?
+
+MyBatis-Spring integrates MyBatis seamlessly with Spring.
+This library allows MyBatis to participate in Spring transactions, takes care of building MyBatis mappers and `SqlSession`s and inject them into other beans, translates MyBatis exceptions into Spring `DataAccessException`s, and finally, it lets you build your application code free of dependencies on MyBatis, Spring or MyBatis-Spring.
+
+## Motivation
+
+Spring version 2 only supports iBATIS version 2. An attempt was made to add MyBatis 3 support into Spring 3 (see the Spring Jira [issue](https://jira.springsource.org/browse/SPR-5991).
+Unfortunately, Spring 3 development ended before MyBatis 3 was officially released. Because the Spring team did not want to release with code based on a non-released version of MyBatis, official Spring support would have to wait.
+Given the interest in Spring support for MyBatis, the MyBatis community decided it was time to reunite the interested contributors and add Spring integration as a community sub-project of MyBatis instead.
+
+## Requirements
+
+Before starting with MyBatis-Spring integration, it is very important that you are familiar with both MyBatis and Spring terminology.
+This document does not attempt to provide background information or basic setup and configuration tutorials for either MyBatis or Spring.
+
+MyBatis-Spring requires following versions:
+
+| MyBatis-Spring | MyBatis | Spring Framework | Spring Batch | Java |
+| --- | --- | --- | --- | --- |
+| **2.0** | 3.5+ | 5.0+ | 4.0+ | Java 8+ |
+| **1.3** | 3.4+ | 3.2.2+ | 2.1+ | Java 6+ |
+
+## Acknowledgements
+
+A special thanks goes to all the special people who made this project a reality (in alphabetical order): Eduardo Macarron, Hunter Presnall and Putthiphong Boonphong for the coding,
+testing and documentation; Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan and Tomas Pinos for their contributions; and Simone Tripodi for finding everyone and bringing them all back to the project under MyBatis ;)
+Without them, this project wouldn't exist.
+
+## Help make this documentation better…
+
+If you find this documentation lacking in any way, or missing documentation for a feature, then the best thing to do is learn about it and then write the documentation yourself!
+
+Sources of this manual are available in markdown format at [project's Git](https://github.com/mybatis/spring/tree/master/src/site) Fork the repository, update them and send a pull request.
+
+You’re the best author of this documentation, people like you have to read it!
+
+## Translations
+
+Users can read about MyBatis-Spring in the following translations:
+
+
+
+Do you want to read about MyBatis in your own native language? Fill an issue providing patches with your mother tongue documentation!
+
diff --git a/src/site/markdown/mappers.md b/src/site/markdown/mappers.md
new file mode 100644
index 0000000000..7153f7385d
--- /dev/null
+++ b/src/site/markdown/mappers.md
@@ -0,0 +1,182 @@
+
+# Injecting Mappers
+
+Rather than code data access objects (DAOs) manually using `SqlSessionDaoSupport` or `SqlSessionTemplate`, Mybatis-Spring can create a thread safe mapper that you can inject directly into other beans:
+
+```xml
+
+
+
+```
+
+Once injected, the mapper is ready to be used in application logic:
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
+
+Notice that there are no `SqlSession` or MyBatis references in this code. Nor is there any need to create, open or close the session, MyBatis-Spring will take care of that.
+
+
+## Registering a mapper
+
+The way you register a mapper depends on whether you are using a classic XML configuration or the new 3.0+ Java Config (a.k.a. `@Configuration`).
+
+### With XML Config
+
+A mapper is registered to Spring by including a `MapperFactoryBean` in your XML config file like follows:
+
+```xml
+
+
+
+
+```
+
+If the UserMapper has a corresponding MyBatis XML mapper file in the same classpath location as the mapper interface, it will be parsed automatically by the `MapperFactoryBean`.
+There is no need to specify the mapper in a MyBatis configuration file unless the mapper XML files are in a different classpath location. See the `SqlSessionFactoryBean`'s `[configLocation](factorybean.html)` property for more information.
+
+Note that `MapperFactoryBean` requires either an `SqlSessionFactory` or an `SqlSessionTemplate`. These can be set through the respective `sqlSessionFactory` and `sqlSessionTemplate` properties.
+If both properties are set, the `SqlSessionFactory` is ignored. Since the `SqlSessionTemplate` is required to have a session factory set, that factory will be used by `MapperFactoryBean`.
+
+### With Java Config
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public MapperFactoryBean userMapper() throws Exception {
+ MapperFactoryBean factoryBean = new MapperFactoryBean<>(UserMapper.class);
+ factoryBean.setSqlSessionFactory(sqlSessionFactory());
+ return factoryBean;
+ }
+}
+```
+
+
+## Scanning for mappers
+
+There is no need to register all your mappers one by one. Instead, you can let MyBatis-Spring scan your classpath for them.
+
+There are three different ways to do it:
+
+* Using the `` element.
+* Using the annotation `@MapperScan`
+* Using a classic Spring xml file and registering the `MapperScannerConfigurer`
+
+Both `` and `@MapperScan` are features introduced in MyBatis-Spring 1.2.0. `@MapperScan` requires Spring 3.1+.
+
+Since 2.0.2, mapper scanning feature support an option (`lazy-initialization`) that control lazy initialization enabled/disabled of mapper bean.
+The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2. The default of this option is `false` (= not use lazy initialization).
+If developer want to use lazy initialization for mapper bean, it should be set to the `true` expressly.
+
+IMPORTANT
+If use the lazy initialization feature, the developer need to understand following limitations. If any of following conditions are matches, usually the lazy initialization feature cannot use on your application.
+
+* When refers to the statement of **other mapper** using ``(`@One`) and ``(`@Many`)
+* When includes to the fragment of **other mapper** using ``
+* When refers to the cache of **other mapper** using ``(`@CacheNamespaceRef`)
+* When refers to the result mapping of **other mapper** using `]]>
-
-
- The previous example makes use of a few different things:
-
-
-
-
sqlSessionFactory: You can specify your own sessionFactory to the reader, it might be
- useful if you want to read from several databases.
-
queryId: If the base code have several tables or databases to read from, and that you have different
- queries, it might be interesting to use different mapper files with different namespaces.
- so when referring to the query, don't forget about the namespace of the mapper file.
-
parameterValues: You can pass additional parameters via this map, the example above uses
- a map that is build by spring using a SpEL expression taking values from the jobExecutionContext.
- The keys of the map will be used by MyBatis in the mapper file (ex:
- yesterday could be used as #{yesterday,jdbcType=TIMESTAMP}).
- Note that the map and the reader are both built in the step scope in order to be able to use
- the Spring EL expression with the jobExecutionContext. Also if MyBatis type handlers
- are correctly configured you can pass custom instances like the parameters of this map that are JodaTime
- dates.
-
pageSize: If the batch flow is configured with chunk size, it is relevant to pass this
- information to the reader as well, which is done via this property.
-
-
-
-
-
-
- This bean is an ItemReader that reads records from a database using a cursor.
-
-
-
- NOTE To use this bean you need at least MyBatis 3.4.0 or a newer version.
-
-
-
- It executes the query specified as the setQueryId property to retrieve requested data
- by using the method selectCursor().
- Each time a read() method is called it will return the next element of the cursor until no more
- elements are left.
-
-
-
- The reader will use a separate connection so the select statement does no participate in any transactions created
- as part of the step processing.
-
-
-
When using the cursor you can just execute a regular query:
-
- SELECT id, name, job FROM employees ORDER BY id ASC
-]]>
-
-
- It is an ItemWriter that uses the batching features from SqlSessionTemplate
- to execute a batch of statements for all items provided.
- The SqlSessionFactory needs to be configured with a BATCH executor.
-
-
-
- When write() is called it executes the mapped statement indicated in the property statementId.
- It is expected that write() is called inside a transaction.
-
Converting a item that read using ItemReader to an any parameter object:
-
-
- By default behavior, the MyBatisBatchItemWriter passes a item that read using ItemReader
- (or convert by ItemProcessor) to the MyBatis(SqlSession#update()) as the parameter object.
- If you want to customize a parameter object that passes to the MyBatis, you can realize to use the itemToParameterConverter option.
- For example using itemToParameterConverter option, you can passes any objects other than the item object to the MyBatis.
- Follows below a sample:
-
-
-
- At first, you create a custom converter class (or factory method). The following sample uses a factory method.
-
Writing to different tables using composite writers (with some caveats):
-
-
This technique can only be used with MyBatis 3.2+, as there was an
- issue in previous
- versions that made the writer misbehave.
-
-
-
If the batch needs to write complex data, like records with associations, or even to different databases, then
- it is possible to work around the fact that insert statements only insert in one table. In order to make it
- happen the batch have to prepare the Item to be written by the writer. However depending on the
- constraints, opportunities or insight on the processed data it might be interesting to use the following technique.
- The following trick can work on items with simple associations or just with unrelated tables.
-
-
-
In a processor craft the Spring Batch Item in such way it will hold all the different records.
- Suppose for each Item there is an Interaction that have one association
- InteractionMetadata, and two non associated rows VisitorInteraction and
- CustomerInteraction, the holder object will look like:
-
-
-
-
-
Then in the spring configuration there will be a CompositeItemWriter that will use delegate
- writers specifically configured for each kind of records. Note that as the InteractionMetadata is
- an association in the example it will need to be written first so that Interaction can have the updated key.
-
Then each delegate writer will be configured as needed; for example for Interaction and
- InteractionMetadata:
-
-
-
-]]>
-
-
Same as the reader the statementId can refer to the statement with the prefixed namespace.
-
-
Now in the mapper file the statement have to be crafted for each kind of records in the following way:
-
-
-
-
-
-
-]]>
-
-
What's happening is that first the insertInteractionMetadata will be called, and the update
- statement is configured to return the ids created by the jdbc driver (keyProperty and keyColumn).
- As the InteractionMetadata object were updated by this query the next query can be used to write the parent
- object Interaction via insertInteraction.
-
-
-
However note that JDBC drivers don't behave the same in this regard. At the time of this writing
- the H2 driver 1.3.168 will only return the latest index even in BATCH mode (see org.h2.jdbc.JdbcStatement#getGeneratedKeys),
- while the MySQL JDBC driver will behave as expected and return all the IDs.
-
- In base MyBatis, the SqlSessionFactory is built using
- SqlSessionFactoryBuilder. In MyBatis-Spring,
- SqlSessionFactoryBean is used instead.
-
-
-
-
- To create the factory bean, put the following in the Spring XML
- configuration file:
-
-
-
-]]>
-
- Note that
- SqlSessionFactoryBean
- implements Spring's
- FactoryBean
- interface (see the Spring documentation(Core Technologies -Customizing instantiation logic with a FactoryBean-)).
- This means that the bean Spring ultimately creates is
- not
- the
- SqlSessionFactoryBean
- itself, but what the
- factory returns as a result of the
- getObject()
- call on
- the factory. In this case, Spring will build an
- SqlSessionFactory
- for you at application startup and
- store it with the name
- sqlSessionFactory
- . In Java, the
- equivalent code would be:
-
-
-
-
-
- In normal MyBatis-Spring usage, you will not need to use
- SqlSessionFactoryBean
- or the corresponding
- SqlSessionFactory
- directly. Instead, the session
- factory will be injected into
- MapperFactoryBeans or
- other DAOs that extend
- SqlSessionDaoSupport
- .
-
-
-
-
-
-
- SqlSessionFactory
- has a single required property, the
- JDBC
- DataSource
- . This can be any
- DataSource
- and should be configured just
- like any other Spring database
- connection.
-
-
-
- One common property is
- configLocation
- which is used to
- specify the location of the MyBatis XML
- configuration file. One case
- where this is needed is if the base
- MyBatis configuration needs to be
- changed. Usually this will be
- <settings>
- or
- <typeAliases>
- sections.
-
-
-
- Note that this config file does
- not
- need to be a
- complete MyBatis config. Specifically, any environments,
- data sources
- and MyBatis transaction managers will be
- ignored
- .
- SqlSessionFactoryBean
- creates its own, custom MyBatis
- Environment
- with these values set as required.
-
-
-
- Another reason to require a config file is if the MyBatis mapper XML
- files are not in the same classpath location as the mapper classes.
- With
- this configuration, there are two options. This first is to
- manually
- specify the classpath of the XML files using a
- <mappers>
- section in the MyBatis config
- file. A second option is to use the
- mapperLocations
- property of the factory bean.
-
-
-
- The
- mapperLocations
- property takes a list of resource
- locations. This property can be
- used to specify the location of MyBatis
- XML mapper files. The value
- can contain Ant-style patterns to load all
- files in a directory or to
- recursively search all paths from a base
- location. For example:
-
-
-
-
-
-]]>
-
-
- This will load all the MyBatis mapper XML files in the
- sample.config.mappers package and its sub-packages from the
- classpath.
-
-
-
- One property that may be required in an environment with container
- managed transactions is
- transactionFactoryClass
- .
- Please see the relevant section in the
- Transactions chapter.
-
-
-
- In case you are using the multi-db feature you will need to set the databaseIdProvider property:
-
- NOTE
- Since 1.3.0, configuration property has been added.
- It can be specified a Configuration instance directly without MyBatis XML configuration file.
- For example:
-
- This chapter will show you in a few steps how to install and setup
- MyBatis-Spring and how to build
- a simple transactional application.
-
-
-
-
- To use the MyBatis-Spring module, you just need to include the
- mybatis-spring-${project.version}.jar
- file and its dependencies in the classpath.
-
-
- If you are using Maven just add the following dependency
- to your
- pom.xml:
-
- To use MyBatis with Spring you need at least two things defined in
- the
- Spring application context: an
- SqlSessionFactory
- and
- at least one mapper interface.
-
-
-
- In MyBatis-Spring, an
- SqlSessionFactoryBean
- is used to
- create an
- SqlSessionFactory
- . To configure the
- factory bean, put the following in the Spring
- configuration file:
-
-
-
-
-]]>
-
-
-
-
- Notice that the
- SqlSessionFactory
- requires a
- DataSource
- . This can be any
- DataSource
- and should be configured just like any other Spring database
- connection.
-
-
-
- Assume you have a mapper interface defined like the following:
-
-
-
-
- This interface is added to Spring using a
- MapperFactoryBean
- like the following:
-
-
-
-
-]]>
-
-
- Note that the mapper class specified
- must
- be an
- interface, not an actual implementation class. In this example,
- annotations are used to specify the SQL, but a MyBatis mapper XML
- file
- could also be used.
-
-
-
- Once configured, you can inject mappers directly into your
- business/service objects in the same way you inject any other Spring
- bean. The MapperFactoryBean
- handles creating an SqlSession
- as well as closing it. If there is a Spring transaction in
- progress,
- the session will also be committed or rolled back when the
- transaction completes. Finally, any exceptions will be translated
- into Spring DataAccessExceptions.
-
-
-
- If you use the Java Configuration:
-
-
-
-
-
- Calling MyBatis data methods is now only one line of code:
-
- MyBatis-Spring integrates MyBatis seamlessly with Spring.
- This library allows MyBatis to participate in Spring transactions, takes care of
- building MyBatis mappers and SqlSessions and inject them into other beans,
- translates MyBatis exceptions into Spring DataAccessExceptions,
- and finally, it lets you build your application code free of
- dependencies on MyBatis, Spring or MyBatis-Spring.
-
-
-
-
-
- Spring version 2 only supports iBATIS version 2. An attempt was made to
- add MyBatis 3 support into Spring 3 (see the Spring Jira
- issue).
- Unfortunately, Spring 3 development ended before MyBatis 3 was
- officially released. Because the Spring team did not want to release with
- code based on a non-released version of MyBatis, official Spring support
- would have to wait. Given the interest in Spring support for MyBatis,
- the MyBatis community decided it was time to reunite the interested contributors
- and add Spring integration as a community sub-project of MyBatis instead.
-
-
-
-
-
- Before starting with MyBatis-Spring integration, it is very important
- that you are familiar with both MyBatis and Spring terminology. This
- document does not attempt to provide background information or basic
- setup and configuration tutorials for either MyBatis or Spring.
-
-
- MyBatis-Spring requires following versions:
-
-
-
-
-
- MyBatis-Spring
-
-
- MyBatis
-
-
- Spring Framework
-
-
- Spring Batch
-
-
- Java
-
-
-
-
-
-
- 2.0
-
-
- 3.5+
-
-
- 5.0+
-
-
- 4.0+
-
-
- Java 8+
-
-
-
-
- 1.3
-
-
- 3.4+
-
-
- 3.2.2+
-
-
- 2.1+
-
-
- Java 6+
-
-
-
-
-
-
-
-
- A special thanks goes to all the special people who made this project
- a reality (in alphabetical order): Eduardo Macarron, Hunter Presnall
- and Putthiphong Boonphong for the coding, testing and documentation;
- Andrius Juozapaitis, Giovanni Cuccu, Mike Lanyon, Raj Nagappan and Tomas Pinos
- for their contributions; and Simone Tripodi for finding everyone and
- bringing them all back to the project under MyBatis ;) Without them,
- this project wouldn't exist.
-
-
-
-
-
- If you find this documentation lacking in any way, or missing
- documentation for a feature, then the best thing to do is learn
- about it and then write the documentation yourself!
-
-
- Sources of this manual are available in xdoc format at
- project's Git
- Fork the repository, update them and send a pull request.
-
-
- You’re the best author of this documentation, people like you have
- to read it!
-
-
-
-
-
Users can read about MyBatis-Spring in the following translations:
- Rather than code data access objects (DAOs) manually using
- SqlSessionDaoSupport or
- SqlSessionTemplate, Mybatis-Spring can create a
- thread safe mapper that you can inject directly into other beans:
-
-
-
-
-]]>
-
-
- Once injected, the mapper is ready to be used in application logic:
-
-
-
- Notice that there are no SqlSession or MyBatis
- references in this code. Nor is there any need to create, open or close
- the session, MyBatis-Spring will take care of that.
-
-
-
-
- The way you register a mapper depends on whether you are using a classic XML configuration
- or the new 3.0+ Java Config (a.k.a. @Configuration).
-
-
With XML Config
-
-
- A mapper is registered to Spring by including a MapperFactoryBean in your XML
- config file like follows:
-
-
-
-
-]]>
-
-
- If the UserMapper has a corresponding MyBatis XML mapper file
- in the same classpath location as the mapper interface, it will be
- parsed automatically by the MapperFactoryBean. There
- is no need to specify the mapper in a MyBatis configuration file unless
- the mapper XML files are in a different classpath location. See the
- SqlSessionFactoryBean's
- configLocation
- property for more information.
-
-
-
- Note that MapperFactoryBean requires either an
- SqlSessionFactory or an SqlSessionTemplate.
- These can be set through the respective sqlSessionFactory and
- sqlSessionTemplate properties.
- If both properties are set, the SqlSessionFactory is ignored.
- Since the SqlSessionTemplate is required to have a session
- factory set, that factory will be used by MapperFactoryBean.
-
- There is no need to register all your mappers one by one.
- Instead, you can let MyBatis-Spring scan your classpath for them.
-
-
-
- There are three different ways to do it:
-
-
-
Using the <mybatis:scan/> element.
-
Using the annotation @MapperScan
-
Using a classic Spring xml file and registering the MapperScannerConfigurer
-
-
-
Both <mybatis:scan/> and @MapperScan are features introduced in MyBatis-Spring 1.2.0.
- @MapperScan requires Spring 3.1+.
-
-
- Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
- that control lazy initialization enabled/disabled of mapper bean.
- The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
- The default of this option is false (= not use lazy initialization).
- If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
-
-
- IMPORTANT If use the lazy initialization feature,
- the developer need to understand following limitations. If any of following conditions are matches,
- usually the lazy initialization feature cannot use on your application.
-
-
-
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
-
When includes to the fragment of other mapper using ]]>
-
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
-
When refers to the result mapping of other mapper using ]]>(@ResultMap)
-
-
-
- NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
-
-
-
-
-
- Since 2.0.6, the develop become can specified scope of mapper using mapper scanning feature option(default-scope)
- and scope annotation(@Scope, @RefreshScope, etc ...).
- The motivation for adding this option is supporting the refresh scope provided by the Spring Cloud.
- The default of this option is empty (= equiv to specify the singleton scope).
- The default-scope apply to the mapper bean(MapperFactoryBean) when scope of scanned bean definition
- is singleton(default scope) and create a scoped proxy bean for scanned mapper when final scope is not singleton.
-
-
-
<mybatis:scan/>
-
-
- The <mybatis:scan/> XML element will search for mappers
- in a very similar way than the Spring built-in element <context:component-scan/>
- searches for beans.
-
-
-
Follows below a sample XML configuration:
-
-
-
-
-
-
-
-]]>
-
-
- The base-package attribute lets you set the base package
- for your mapper interface files. You can set more than one package by
- using a semicolon or comma as a separator. Mappers will be searched for
- recursively starting in the specified package(s).
-
-
-
- Notice that there is no need to specify a SqlSessionFactory or
- SqlSessionTemplate as an attribute in the <mybatis:scan/>
- element because it will create MapperFactoryBeans that can be autowired.
- But if you are using more than one DataSource autowire may not work for you.
- In this case you can use the factory-ref or
- template-ref attributes to set the right bean name to use.
-
-
-
- <mybatis:scan/> supports filtering the mappers
- created by either specifying a marker interface or an annotation. The
- annotation property specifies an annotation to
- search for. The marker-interface attribute specifies a
- parent interface to search for. If both properties are specified, mappers
- are added for interfaces that match either criteria.
- By default, these two properties are null, so all interfaces in the given
- base package(s) will be loaded as mappers.
-
-
-
- Discovered mappers will be named using Spring default naming strategy for
- autodetected components (see the Spring reference document(Core Technologies -Naming autodetected components-)).
- That is, if no annotation is found, it will use the uncapitalized non-qualified class
- name of the mapper. But if either a @Component or a JSR-330 @Named annotation is
- found it will get the name from the annotation.
- Notice that you can set the annotation attribute
- to org.springframework.stereotype.Component,
- javax.inject.Named (if you have JSE 6) or to your own annotation
- (that must be itself annotated) so the annotation will work both as a marker
- and as a name provider.
-
-
-
- NOTE<context:component-scan/>
- won't be able to scan and register mappers. Mappers are interfaces and, in order to register them to
- Spring, the scanner must know how to create a MapperFactoryBean for each interface
- it finds.
-
-
-
@MapperScan
-
-
- If you are using the Spring Java Configuration (a.k.a @Configuration) you would
- prefer to use the @MapperScan rather than the
- <mybatis:scan/>.
-
-
-
The @MapperScan annotation is used as follows:
-
-
-
-
The annotation works in the same exact way than <mybatis:scan/> we
- saw in the previous section. It also lets you specify a marker interface or an annotation class
- through its properties markerInterface and annotationClass.
- You can also provide an specific SqlSessionFactory or SqlSessionTemplate
- by using its properties sqlSessionFactory and sqlSessionTemplate.
-
-
-
- NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
-
-
-
MapperScannerConfigurer
-
-
- The MapperScannerConfigurer is a BeanDefinitionRegistryPostProcessor that
- can be included in a classic xml application context as a normal bean.
- To set up a MapperScannerConfigurer add the following to the Spring configuration:
-
-
-
-]]>
-
-
- If you need to specify an specific sqlSessionFactory or sqlSessionTemplate
- note that bean names are required,
- not bean references, thus the value attribute is used instead of the
- usual ref:
-
- ]]>
-
-
- NOTEsqlSessionFactoryBean and
- sqlSessionTemplateBean properties were the only option available up to MyBatis-Spring 1.0.2
- but given that the MapperScannerConfigurer runs earlier in the startup
- process that PropertyPlaceholderConfigurer there were frequent errors.
- For that purpose that properties have been deprecated and the new properties
- sqlSessionFactoryBeanName and sqlSessionTemplateBeanName
- are recommended.
-
- NOTE
- See JPetstore 6 demo to know about how to use Spring with a full web application server.
-
-
-
- You can check out sample code from the MyBatis-Spring repo:
-
-
- Any of the samples can be run with JUnit 5.
-
-
- The sample code shows a typical design where a transactional service gets domain objects from a data access layer.
-
-
- FooService.java acts as the service:
-
-
-
- It is a transactional bean, so when the method is called, the transaction is started
- and the transaction is committed when the method ends without throwing an uncaught exception.
- Notice that transactional behaviour is configured with the
- @Transactional
- attribute. This is not required; any other way provided by Spring can be used to demarcate
- your transactions.
-
-
- This service calls a data access layer built with MyBatis. This layer
- consists on a just an interface UserMapper.java
- that will be used with a dynamic proxy built by MyBatis at
- runtime and injected into the service by Spring.
-
-
-
- Note that, for the sake of simplicity we used the interface UserMapper.java for the DAO scenario
- where a DAO is built with an interface and a implementation though in this case it would have been more
- adequate to use an interface called UserDao.java instead.
-
-
- We will see different ways to find the mapper interface, register it to Spring and inject it into the service bean:
-
-
-
Scenarios
-
-
-
Sample test
-
Description
-
-
-
-
-
- SampleMapperTest.java
-
-
- Shows you the base configuration based on a MapperFactoryBean
- that will dynamically build an implementation for UserMapper
-
-
-
-
- SampleScannerTest.java
-
-
- Shows how to use the MapperScannerConfigurer so all the mappers in a project are autodiscovered.
-
-
-
-
- SampleSqlSessionTest.java
-
-
- Shows how to hand code a DAO using a Spring managed SqlSession
- and providing your own implementation UserDaoImpl.java.
-
-
-
-
- SampleEnableTest
-
-
- Shows how to use Spring's @Configuration with the @MapperScann annotation so
- mappers are autodiscovered.
-
-
-
-
- SampleNamespaceTest
-
-
- Shows how to use the custom MyBatis XML namespace.
-
-
-
-
- SampleJavaConfigTest.java
-
-
- Shows how to use Spring's @Configuration to create MyBatis beans manually.
-
-
-
-
- SampleJobJavaConfigTest.java
-
-
- Shows how to use ItemReader and ItemWriter on Spring Batch using Java Configuration.
-
-
-
-
- SampleJobXmlConfigTest.java
-
-
- Shows how to use ItemReader and ItemWriter on Spring Batch using XML Configuration.
-
-
-
-
-
- Please take a look at the different applicationContext.xml files to see MyBatis-Spring in action.
-
- In MyBatis you use the SqlSessionFactory to create an
- SqlSession. Once you have a session, you use it to
- execute your mapped statements, commit or rollback connections and
- finally, when it is no longer needed, you close the session. With
- MyBatis-Spring you don't need to use SqlSessionFactory
- directly because your beans can be injected with a thread safe
- SqlSession that automatically commits, rollbacks and
- closes the session based on Spring's transaction configuration.
-
-
-
-
- SqlSessionTemplate is the heart of MyBatis-Spring.
- It implements SqlSession and is meant to be a drop-in replacement
- for any existing use of SqlSession in your code.
- SqlSessionTemplate is thread safe and can be shared
- by multiple DAOs or mappers.
-
-
-
- When calling SQL methods, including any method from Mappers returned by
- getMapper(), SqlSessionTemplate
- will ensure that the SqlSession used is the one
- associated with the current Spring transaction. In addition, it manages
- the session life-cycle, including closing, committing or rolling back the
- session as necessary. It will also translate MyBatis exceptions
- into Spring DataAccessExceptions.
-
-
-
- SqlSessionTemplate should always
- be used instead of default MyBatis implementation DefaultSqlSession
- because the template can participate in Spring transactions and is thread safe for use by
- multiple injected mapper classes. Switching between the two classes in the
- same application can cause data integrity issues.
-
-
-
- A SqlSessionTemplate can be constructed
- using an SqlSessionFactory as a constructor argument.
-
-
-
-]]>
-
-
-
-
- This bean can now be injected directly in your DAO beans. You need a
- SqlSession property in your bean like the following
-
-
-
- And inject the SqlSessionTemplate as follows
-
-
-
-]]>
-
-
- SqlSessionTemplate has also a constructor that takes
- an ExecutorType as an argument. This allows you to
- construct, for example, a batch SqlSession by using
- the following in Spring's configuration file:
-
-
-
-
-]]>
-
-
-
-
- Now all your statements will be batched so the following could be coded
- in a DAO
-
- users) {
- for (User user : users) {
- sqlSession.insert("org.mybatis.spring.sample.mapper.UserMapper.insertUser", user);
- }
-}]]>
-
-
- Note that this configuration style only needs to be used if the desired
- execution method differs from the default set for the
- SqlSessionFactory.
-
-
-
- The caveat to this form is that
- there cannot be an existing transaction running with
- a different ExecutorType when this method is called. Either ensure that
- calls to SqlSessionTemplates with different executor
- types run in a separate transaction (e.g. with PROPAGATION_REQUIRES_NEW) or
- completely outside of a transaction.
-
-
-
-
-
- SqlSessionDaoSupport is an abstract support class that
- provides you with a SqlSession. Calling
- getSqlSession() you will get a SqlSessionTemplate
- which can then be used to execute SQL methods, like the following:
-
-
-
- Usually MapperFactoryBean is preferred to this class,
- since it requires no extra code. But, this class is useful if you need
- to do other non-MyBatis work in your DAO and concrete classes are
- required.
-
-
-
- SqlSessionDaoSupport requires either an
- sqlSessionFactory or an sqlSessionTemplate
- property to be set.
- If both properties are set, the sqlSessionFactory is ignored.
-
-
-
- Assuming a class UserDaoImpl that subclasses
- SqlSessionDaoSupport, it can be configured in Spring
- like the following:
-
- One of the primary reasons for using MyBatis-Spring is that it allows
- MyBatis to participate in Spring transactions. Rather than create a new
- transaction manager specific to MyBatis, MyBatis-Spring leverages the
- existing DataSourceTransactionManager in Spring.
-
-
- Once a Spring transaction manager is configured, you can configure
- transactions in Spring as you normally would. Both
- @Transactional annotations and AOP style
- configurations are supported. A single SqlSession
- object will be created and used for the duration of the transaction. This
- session will be committed or rolled back as appropriate when then
- transaction completes.
-
-
- MyBatis-Spring will transparently manage transactions once they are set up.
- There is no need for additional code in your DAO classes.
-
-
-
-
- To enable Spring transaction processing, simply create a
- DataSourceTransactionManager in your Spring
- configuration file:
-
-
-
-
-]]>
-
-
-
-
- The DataSource specified can be any JDBC
- DataSource you would normally
- use with Spring. This includes connection pools as well as DataSources
- obtained through JNDI lookups.
-
-
- Note that the DataSource specified for the transaction
- manager must be the same one that is used to create
- the SqlSessionFactoryBean or transaction management will
- not work.
-
-
-
-
-
- If you are using a JEE container and would like Spring to participate in
- container managed transactions (CMT), then Spring should be configured
- with a JtaTransactionManager or one of its container
- specific subclasses. The easiest way to do this is to use the Spring
- transaction namespace or the JtaTransactionManagerFactoryBean:
-
- ]]>
-
-
-
-
- In this configuration, MyBatis will behave like any other Spring
- transactional resource configured with CMT. Spring will automatically use
- any existing container transaction and attach an SqlSession to it. If no
- transaction is started and one is needed based on the transaction
- configuration, Spring will start a new container managed transaction.
-
-
- Note that if you want to use CMT and do not want to
- use Spring transaction management, you must not
- configure any Spring transaction manager and you must
- also configure the SqlSessionFactoryBean to use the base
- MyBatis ManagedTransactionFactory:
-
-
-
-
-
-
-]]>
-
-
-
-
-
-
- MyBatis SqlSession provides you with specific methods to handle
- transactions programmatically. But when using MyBatis-Spring your beans will be
- injected with a Spring managed SqlSession or a Spring managed mapper.
- That means that Spring will always handle your transactions.
-
-
- You cannot call SqlSession.commit(), SqlSession.rollback()
- or SqlSession.close() over a Spring managed SqlSession.
- If you try to do so, a UnsupportedOperationException exception
- will be thrown. Note these methods are not exposed in injected mapper classes.
-
-
- Regardless of your JDBC connection's autocommit setting, any execution of a
- SqlSession data method or any call to a mapper
- method outside a Spring transaction will be automatically committed.
-
- With MyBatis-Spring, you can continue to directly use the MyBatis API.
- Simply create an SqlSessionFactory in Spring using
- SqlSessionFactoryBean and use the factory in your code.
-
-
-
-
- Use this option with care because wrong usage may produce runtime errors or
- worse, data integrity problems. Be aware of the following caveats with direct API usage:
-
-
-
-
- It will not participate in any Spring transactions.
-
-
-
-
- If the SqlSession is using a DataSource
- that is also being used by a Spring transaction manager and there is currently
- a transaction in progress, this code will throw an exception.
-
-
-
-
- MyBatis' DefaultSqlSession is not thread safe. If you
- inject it in your beans you will get errors.
-
-
-
-
- Mappers created using DefaultSqlSession are not thread safe either.
- If you inject them it in your beans you will get errors.
-
-
-
-
- You must make sure that your SqlSessions
- are always closed in a finally block.
-
+
+想用自己的母语阅读这篇文档吗?那就用你的母语翻译它吧!
diff --git a/src/site/zh/markdown/mappers.md b/src/site/zh/markdown/mappers.md
new file mode 100644
index 0000000000..2be7d90375
--- /dev/null
+++ b/src/site/zh/markdown/mappers.md
@@ -0,0 +1,183 @@
+
+# 注入映射器
+
+与其在数据访问对象(DAO)中手工编写使用 `SqlSessionDaoSupport` 或 `SqlSessionTemplate` 的代码,还不如让 Mybatis-Spring 为你创建一个线程安全的映射器,这样你就可以直接注入到其它的 bean 中了:
+
+```xml
+
+
+
+```
+
+注入完毕后,映射器就可以在你的应用逻辑代码中使用了:
+
+```java
+public class FooServiceImpl implements FooService {
+
+ private final UserMapper userMapper;
+
+ public FooServiceImpl(UserMapper userMapper) {
+ this.userMapper = userMapper;
+ }
+
+ public User doSomeBusinessStuff(String userId) {
+ return this.userMapper.getUser(userId);
+ }
+}
+```
+
+注意代码中并没有任何的对 `SqlSession` 或 MyBatis 的引用。你也不需要担心创建、打开、关闭 session,MyBatis-Spring 将为你打理好一切。
+
+
+## 注册映射器
+
+注册映射器的方法根据你的配置方法,即经典的 XML 配置或新的 3.0 以上版本的 Java 配置(也就是常说的 `@Configuration`),而有所不同。
+
+### XML 配置
+
+在你的 XML 中加入 `MapperFactoryBean` 以便将映射器注册到 Spring 中。就像下面一样:
+
+```xml
+
+
+
+
+```
+
+如果映射器接口 UserMapper 在相同的类路径下有对应的 MyBatis XML 映射器配置文件,将会被 `MapperFactoryBean` 自动解析。不需要在 MyBatis 配置文件中显式配置映射器,除非映射器配置文件与接口类不在同一个类路径下。
+参考 `SqlSessionFactoryBean` 的 [`configLocation`](factorybean.html) 属性以获取更多信息。
+
+注意 `MapperFactoryBean` 需要配置一个 `SqlSessionFactory` 或 `SqlSessionTemplate`。它们可以分别通过 `sqlSessionFactory` 和 `sqlSessionTemplate` 属性来进行设置。
+如果两者都被设置,`SqlSessionFactory` 将被忽略。由于 `SqlSessionTemplate` 已经设置了一个 session 工厂,`MapperFactoryBean` 将使用那个工厂。
+
+### Java 配置
+
+```java
+@Configuration
+public class MyBatisConfig {
+ @Bean
+ public MapperFactoryBean userMapper() throws Exception {
+ MapperFactoryBean factoryBean = new MapperFactoryBean<>(UserMapper.class);
+ factoryBean.setSqlSessionFactory(sqlSessionFactory());
+ return factoryBean;
+ }
+}
+```
+
+
+## 发现映射器
+
+不需要一个个地注册你的所有映射器。你可以让 MyBatis-Spring 对类路径进行扫描来发现它们。
+
+
+有几种办法来发现映射器:
+
+* 使用 `` 元素
+* 使用 `@MapperScan` 注解
+* 在经典 Spring XML 配置文件中注册一个 `MapperScannerConfigurer`
+
+`` 和 `@MapperScan` 都在 MyBatis-Spring 1.2.0 中被引入。`@MapperScan` 需要你使用 Spring 3.1+。
+
+Since 2.0.2, mapper scanning feature support a option (`lazy-initialization`) that control lazy initialization enabled/disabled of mapper bean.
+The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2. The default of this option is `false` (= not use lazy initialization).
+If developer want to use lazy initialization for mapper bean, it should be set to the `true` expressly.
+
+IMPORTANT
+If use the lazy initialization feature, the developer need to understand following limitations.
+If any of following conditions are matches, usually the lazy initialization feature cannot use on your application.
+
+* When refers to the statement of **other mapper** using ``(`@One`) and ``(`@Many`)
+* When includes to the fragment of **other mapper** using ``
+* When refers to the cache of **other mapper** using ``(`@CacheNamespaceRef`)
+* When refers to the result mapping of **other mapper** using `]]>
-
-
- MyBatis-Spring 会帮助你将 MyBatis 代码无缝地整合到 Spring 中。它将允许 MyBatis 参与到 Spring 的事务管理之中,创建映射器 mapper 和 SqlSession 并注入到 bean 中,以及将 Mybatis 的异常转换为 Spring 的 DataAccessException。最终,可以做到应用代码不依赖于 MyBatis,Spring 或 MyBatis-Spring。
-
-
-
-
-
- Spring 2.0 只支持 iBatis 2.0。那么,我们就想将 MyBatis3 的支持添加到 Spring 3.0 中(参见 Spring Jira 中的问题)。不幸的是,Spring 3.0 的开发在 MyBatis 3.0 官方发布前就结束了。由于 Spring 开发团队不想发布一个基于未发布版的 MyBatis 的整合支持,如果要获得 Spring 官方的支持,只能等待下一次的发布了。基于在 Spring 中对 MyBatis 提供支持的兴趣,MyBatis 社区认为,应该开始召集有兴趣参与其中的贡献者们,将对 Spring 的集成作为 MyBatis 的一个社区子项目。
-
-
-
-
-
- 在开始使用 MyBatis-Spring 之前,你需要先熟悉 Spring 和 MyBatis 这两个框架和有关它们的术语。这很重要——因为本手册中不会提供二者的基本内容,安装和配置教程。
-
<mybatis:scan/> 和 @MapperScan 都在 MyBatis-Spring 1.2.0 中被引入。@MapperScan 需要你使用 Spring 3.1+。
-
-
- Since 2.0.2, mapper scanning feature support a option (lazy-initialization)
- that control lazy initialization enabled/disabled of mapper bean.
- The motivation for adding this option is supporting a lazy initialization control feature supported by Spring Boot 2.2.
- The default of this option is false (= not use lazy initialization).
- If developer want to use lazy initialization for mapper bean, it should be set to the true expressly.
-
-
- IMPORTANT If use the lazy initialization feature,
- the developer need to understand following limitations. If any of following conditions are matches,
- usually the lazy initialization feature cannot use on your application.
-
-
-
When refers to the statement of other mapper using ]]>(@One) and ]]>(@Many)
-
When includes to the fragment of other mapper using ]]>
-
When refers to the cache of other mapper using ]]>(@CacheNamespaceRef)
-
When refers to the result mapping of other mapper using ]]>(@ResultMap)
-
-
-
- NOTE However, It become possible to use it by simultaneously initializing dependent beans using @DependsOn(Spring's feature) as follow:
-
-
-
-
-
- Since 2.0.6, the develop become can specified scope of mapper using mapper scanning feature option(default-scope)
- and scope annotation(@Scope, @RefreshScope, etc ...).
- The motivation for adding this option is supporting the refresh scope provided by the Spring Cloud.
- The default of this option is empty (= equiv to specify the singleton scope).
- The default-scope apply to the mapper bean(MapperFactoryBean) when scope of scanned bean definition
- is singleton(default scope) and create a scoped proxy bean for scanned mapper when final scope is not singleton.
-
-
-
<mybatis:scan/>
-
-
- <mybatis:scan/> 元素会发现映射器,它发现映射器的方法与 Spring 内建的 <context:component-scan/> 发现 bean 的方法非常类似。
-
- NOTE Since 2.0.4, If basePackageClasses or basePackages are not defined, scanning will occur from the package of the class that declares this annotation.
-
-
-
MapperScannerConfigurer
-
-
- MapperScannerConfigurer 是一个 BeanDefinitionRegistryPostProcessor,这样就可以作为一个 bean,包含在经典的 XML 应用上下文中。为了配置 MapperScannerConfigurer,使用下面的 Spring 配置:
-