CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-mybatis-spring-boot--mybatis-spring-boot-starter

Spring Boot Starter for MyBatis integration providing auto-configuration and dependency management

Pending
Overview
Eval results
Files

configuration-properties.mddocs/

Configuration Properties

The MyBatis Spring Boot Starter provides comprehensive configuration through Spring Boot's properties system, allowing you to configure all aspects of MyBatis behavior using application.properties or application.yml files.

Capabilities

MybatisProperties

Main configuration properties class that binds all mybatis.* properties to MyBatis settings.

import org.apache.ibatis.scripting.LanguageDriver;
import org.apache.ibatis.session.ExecutorType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
import java.util.Properties;

/**
 * Configuration properties for MyBatis integration with Spring Boot
 */
@ConfigurationProperties(prefix = MybatisProperties.MYBATIS_PREFIX)
public class MybatisProperties {
    public static final String MYBATIS_PREFIX = "mybatis";
    
    /** Location of MyBatis xml config file */
    private String configLocation;
    
    /** Locations of MyBatis mapper files */
    private String[] mapperLocations;
    
    /** Packages to search type aliases (Package delimiters are ",; \t\n") */
    private String typeAliasesPackage;
    
    /** Super class for filtering type alias */
    private Class<?> typeAliasesSuperType;
    
    /** Packages to search for type handlers (Package delimiters are ",; \t\n") */
    private String typeHandlersPackage;
    
    /** Whether to perform presence check of MyBatis xml config file */
    private boolean checkConfigLocation;
    
    /** Execution mode for SqlSessionTemplate */
    private ExecutorType executorType;
    
    /** Default scripting language driver class */
    private Class<? extends LanguageDriver> defaultScriptingLanguageDriver;
    
    /** Externalized properties for MyBatis configuration */
    private Properties configurationProperties;
    
    /** Configuration object for customize default settings */
    private CoreConfiguration configuration;
    
    // Getters and setters for all properties
    public String getConfigLocation();
    public void setConfigLocation(String configLocation);
    public String[] getMapperLocations();
    public void setMapperLocations(String[] mapperLocations);
    public String getTypeAliasesPackage();
    public void setTypeAliasesPackage(String typeAliasesPackage);
    public Class<?> getTypeAliasesSuperType();
    public void setTypeAliasesSuperType(Class<?> typeAliasesSuperType);
    public String getTypeHandlersPackage();
    public void setTypeHandlersPackage(String typeHandlersPackage);
    public boolean isCheckConfigLocation();
    public void setCheckConfigLocation(boolean checkConfigLocation);
    public ExecutorType getExecutorType();
    public void setExecutorType(ExecutorType executorType);
    public Class<? extends LanguageDriver> getDefaultScriptingLanguageDriver();
    public void setDefaultScriptingLanguageDriver(Class<? extends LanguageDriver> defaultScriptingLanguageDriver);
    public Properties getConfigurationProperties();
    public void setConfigurationProperties(Properties configurationProperties);
    public CoreConfiguration getConfiguration();
    public void setConfiguration(CoreConfiguration configuration);
    
    /** Resolves mapper location patterns to actual Resource objects */
    public Resource[] resolveMapperLocations();
}

Usage Examples:

# Basic MyBatis configuration
mybatis.config-location=classpath:mybatis-config.xml
mybatis.mapper-locations=classpath:mappers/*.xml
mybatis.type-aliases-package=com.example.model
mybatis.type-handlers-package=com.example.handlers
mybatis.check-config-location=true

# Executor configuration
mybatis.executor-type=simple

# Custom configuration properties
mybatis.configuration-properties.key1=value1
mybatis.configuration-properties.key2=value2

CoreConfiguration

Nested configuration class for MyBatis core module settings, providing access to all internal MyBatis configuration options.

import org.apache.ibatis.io.VFS;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.AutoMappingBehavior;
import org.apache.ibatis.session.AutoMappingUnknownColumnBehavior;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.LocalCacheScope;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import java.util.Properties;
import java.util.Set;

/**
 * Configuration properties for MyBatis core module
 */
public static class CoreConfiguration {
    /** Allows using RowBounds on nested statements */
    private Boolean safeRowBoundsEnabled;
    
    /** Allows using ResultHandler on nested statements */
    private Boolean safeResultHandlerEnabled;
    
    /** Enables automatic mapping from database column names to camel case */
    private Boolean mapUnderscoreToCamelCase;
    
    /** When enabled, any method call will load all lazy properties */
    private Boolean aggressiveLazyLoading;
    
    /** Allows multiple ResultSets from a single statement */
    private Boolean multipleResultSetsEnabled;
    
    /** Allows JDBC support for generated keys */
    private Boolean useGeneratedKeys;
    
    /** Uses column label instead of column name */
    private Boolean useColumnLabel;
    
    /** Globally enables or disables any caches */
    private Boolean cacheEnabled;
    
    /** Specifies if setters will be called when retrieved value is null */
    private Boolean callSettersOnNulls;
    
    /** Allow referencing statement parameters by their actual names */
    private Boolean useActualParamName;
    
    /** Returns empty instance instead of null when all columns are NULL */
    private Boolean returnInstanceForEmptyRow;
    
    /** Removes extra whitespace characters from SQL */
    private Boolean shrinkWhitespacesInSql;
    
    /** Default value of 'nullable' attribute on 'foreach' tag */
    private Boolean nullableOnForEach;
    
    /** Uses argument name for constructor auto-mapping */
    private Boolean argNameBasedConstructorAutoMapping;
    
    /** Globally enables or disables lazy loading */
    private Boolean lazyLoadingEnabled;
    
    /** Number of seconds driver will wait for response */
    private Integer defaultStatementTimeout;
    
    /** Driver hint for fetching size */
    private Integer defaultFetchSize;
    
    /** MyBatis local cache scope (SESSION or STATEMENT) */
    private LocalCacheScope localCacheScope;
    
    /** JDBC type for null values */
    private JdbcType jdbcTypeForNull;
    
    /** Scroll strategy when omit per statement settings */
    private ResultSetType defaultResultSetType;
    
    /** Configures the default executor (SIMPLE, REUSE, BATCH) */
    private ExecutorType defaultExecutorType;
    
    /** How MyBatis should automatically map columns to fields */
    private AutoMappingBehavior autoMappingBehavior;
    
    /** Behavior when detects unknown column of automatic mapping target */
    private AutoMappingUnknownColumnBehavior autoMappingUnknownColumnBehavior;
    
    /** Prefix string for logger names */
    private String logPrefix;
    
    /** Methods that trigger lazy load */
    private Set<String> lazyLoadTriggerMethods;
    
    /** Logging implementation */
    private Class<? extends Log> logImpl;
    
    /** VFS implementations */
    private Class<? extends VFS> vfsImpl;
    
    /** Default SQL provider class */
    private Class<?> defaultSqlProviderType;
    
    /** Default TypeHandler for Enum */
    private Class<? extends TypeHandler> defaultEnumTypeHandler;
    
    /** Class that provides Configuration instance */
    private Class<?> configurationFactory;
    
    /** Configuration variables */
    private Properties variables;
    
    /** Database identify value for switching query */
    private String databaseId;
    
    // All getter and setter methods...
    public Boolean getSafeRowBoundsEnabled();
    public void setSafeRowBoundsEnabled(Boolean safeRowBoundsEnabled);
    public Boolean getSafeResultHandlerEnabled();
    public void setSafeResultHandlerEnabled(Boolean safeResultHandlerEnabled);
    // ... all other getters and setters
    
    /** Applies this configuration to a MyBatis Configuration object */
    public void applyTo(Configuration target);
}

Usage Examples:

# Core MyBatis configuration through Spring Boot properties
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.cache-enabled=true
mybatis.configuration.lazy-loading-enabled=true
mybatis.configuration.aggressive-lazy-loading=false
mybatis.configuration.use-generated-keys=true
mybatis.configuration.default-executor-type=simple
mybatis.configuration.default-statement-timeout=30
mybatis.configuration.default-fetch-size=100
mybatis.configuration.safe-row-bounds-enabled=false
mybatis.configuration.safe-result-handler-enabled=true
mybatis.configuration.use-column-label=true
mybatis.configuration.use-actual-param-name=true
mybatis.configuration.return-instance-for-empty-row=false
mybatis.configuration.shrink-whitespaces-in-sql=false
mybatis.configuration.nullable-on-for-each=false
mybatis.configuration.arg-name-based-constructor-auto-mapping=false
mybatis.configuration.auto-mapping-behavior=partial
mybatis.configuration.auto-mapping-unknown-column-behavior=none
mybatis.configuration.local-cache-scope=session
mybatis.configuration.jdbc-type-for-null=other
mybatis.configuration.log-prefix=mybatis.
mybatis.configuration.variables.key1=value1
mybatis.configuration.database-id=mysql

Additional Configuration Properties

Starter-Specific Properties

Additional properties specific to the Spring Boot integration:

# Enable lazy initialization for mapper beans
mybatis.lazy-initialization=false

# Default scope for auto-configured mapper beans
mybatis.mapper-default-scope=

# Whether to inject SqlSession on mapper scan (for spring-native compatibility)
mybatis.inject-sql-session-on-mapper-scan=true

Scripting Language Driver Properties

Configuration for additional scripting language drivers:

# FreeMarker scripting language driver
mybatis.scripting-language-driver.freemarker.base-package-to-scan=
mybatis.scripting-language-driver.freemarker.freemarker-settings.locale=en_US

# Velocity scripting language driver  
mybatis.scripting-language-driver.velocity.velocity-settings.resource.loader=class

# Thymeleaf scripting language driver
mybatis.scripting-language-driver.thymeleaf.use-3x-syntax=true
mybatis.scripting-language-driver.thymeleaf.dialect.prefix=mb

Install with Tessl CLI

npx tessl i tessl/maven-org-mybatis-spring-boot--mybatis-spring-boot-starter

docs

auto-configuration.md

configuration-properties.md

customization.md

index.md

testing-support.md

tile.json