All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fangjinuo.sqlhelper.mybatis.spring.boot.autoconfigure.SqlHelperMybatisAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.1-RELEASE
Show newest version
/*
 * Copyright 2019 the original author or authors.
 *
 * Licensed under the LGPL, Version 3.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.gnu.org/licenses/lgpl-3.0.html
 *
 * 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 com.github.fangjinuo.sqlhelper.mybatis.spring.boot.autoconfigure;

import com.github.fangjinuo.sqlhelper.mybatis.MybatisUtils;
import com.github.fangjinuo.sqlhelper.mybatis.plugins.pagination.CustomScriptLanguageDriver;
import com.github.fangjinuo.sqlhelper.mybatis.plugins.pagination.MybatisPaginationPlugin;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@org.springframework.context.annotation.Configuration
@EnableConfigurationProperties(SqlHelperMybatisProperties.class)
@AutoConfigureBefore(MybatisAutoConfiguration.class)
public class SqlHelperMybatisAutoConfiguration implements ConfigurationCustomizer {
    private static final Logger logger = LoggerFactory.getLogger(SqlHelperMybatisAutoConfiguration.class);

    @Bean
    public DatabaseIdProvider databaseIdProvider() {
        return MybatisUtils.vendorDatabaseIdProvider();
    }

    private SqlHelperMybatisProperties sqlHelperMybatisProperties;

    @Autowired
    public void setSqlHelperMybatisProperties(SqlHelperMybatisProperties sqlHelperMybatisProperties) {
        this.sqlHelperMybatisProperties = sqlHelperMybatisProperties;
    }

    @Override
    public void customize(Configuration configuration) {
        logger.info("Start to customize mybatis configuration with mybatis-spring-boot-autoconfigure");
        configuration.setDefaultScriptingLanguage(CustomScriptLanguageDriver.class);

        MybatisPaginationPlugin plugin = new MybatisPaginationPlugin();
        plugin.setPaginationPluginConfig(sqlHelperMybatisProperties.getPagination());
        plugin.setInstrumentorConfig(sqlHelperMybatisProperties.getInstrumentor());
        plugin.init();

        logger.info("Add interceptor {} to mybatis configuration", plugin);
        configuration.addInterceptor(plugin);
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy