com.wuzh.commons.mybatis.MyBatisConfig Maven / Gradle / Ivy
/*
* Copyright 2015-2022 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 com.wuzh.commons.mybatis;
import com.wuzh.commons.mybatis.constants.DataSourceConstants;
import com.wuzh.commons.mybatis.datasource.DruidDataSourceConfig;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScannerRegistrar;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
/**
* 类MyBatisConfig的实现描述:MyBatis配置
*
* @author 伍章红 2019-12-20 12:56:44
* @version v2.2.0
* @since JDK 1.8
*/
@Configuration
@Import({DruidDataSourceConfig.class})
public class MyBatisConfig {
private final Logger logger = LoggerFactory.getLogger(MyBatisConfig.class);
/**
* MAPPER映射器文件存放路径
*/
private final String MAPPER_LOCATION = "classpath:com/wuzh/**/mapper/**/*.xml";
/**
* MAPPER接口文件存放路径
*
* @since v2.3.6
*/
private final String MAPPER_PACKAGE = "com.wuzh.**.mapper";
/**
* 配置文件信息
*/
private final String CONFIG_LOCATION = "/META-INF/mybatis-config.xml";
/**
* 实体类所在包
*/
private final String TYPE_ALIASES_PACKAGE = "com.wuzh.**.entity";
@Bean(name = "dataSource")
public DataSource dataSource(@Qualifier("writeDataSource") DataSource writeDataSource,
@Qualifier("readDataSource") DataSource readDataSource) {
Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy