package com.ygq.report.config;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import com.alibaba.druid.pool.DruidDataSource;
import com.ygq.report.util.MybatisMapperDynamicLoader;

/**
 * @description core包数据库连接配置
 * @time 2017年9月25日 下午3:47:29
 */
@Configuration
@EnableAutoConfiguration
public class DruidConfig {

	@Value("${spring.datasource.dburl}")
	private String dburl;

	@Value("${spring.datasource.dbusername}")
	private String dbusername;

	@Value("${spring.datasource.password}")
	private String password;

	/**
	 * Druid 数据源配置
	 *
	 * @param dburl
	 * @param dbusername
	 * @param password
	 * @return
	 * @throws SQLException
	 */
	@Bean(initMethod = "init", destroyMethod = "close")
	public DataSource druidDataSource() throws SQLException {
		DruidDataSource druidDataSource = new DruidDataSource();
		druidDataSource.setUrl(dburl);
		druidDataSource.setUsername(dbusername);
		druidDataSource.setPassword(password);
		druidDataSource.setInitialSize(10);// 初始化时建立物理连接的个数。
		druidDataSource.setMaxActive(30);// 最大连接池数量
		druidDataSource.setMinIdle(10);// 最小连接池数量
		druidDataSource.setRemoveAbandoned(true);// 是否自动回收超时连接
		druidDataSource.setRemoveAbandonedTimeout(600);// 自动回收超时时间
		druidDataSource.setLogAbandoned(true);// 关闭abanded连接时输出错误日志
		return druidDataSource;
	}

	@Bean
	public SqlSessionFactory sqlSessionFactory() throws Exception {
		SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
		bean.setDataSource(druidDataSource());
		bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:/sqlTemplet/*.xml"));
		return bean.getObject();
	}
    
	@Bean
	public MybatisMapperDynamicLoader mybatisMapperDynamicLoader() throws Exception {
		MybatisMapperDynamicLoader mybatisMapperDynamicLoader=new MybatisMapperDynamicLoader();
		return mybatisMapperDynamicLoader;
	}
	
//	@Bean
//	public RefreshMapperCache refreshMapperCache() throws Exception {
//		RefreshMapperCache refreshMapperCache=new RefreshMapperCache();
//		refreshMapperCache.setPackageSearchPath("classpath*:sqlTemplet/*.xml");
//		refreshMapperCache.setSqlSessionFactory(sqlSessionFactory());
//		return refreshMapperCache;
//	}
}
最近下载更多
a1w4fsdaf  LV9 2023年4月7日
是你爸爸啊100  LV5 2022年8月8日
*  LV4 2022年4月20日
test12312321  LV14 2022年2月23日
mafangnu  LV8 2021年10月7日
wcy071213  LV27 2021年8月22日
huaua7676  LV30 2021年7月20日
lodddy  LV6 2021年5月11日
liuxie  LV12 2021年4月29日
a792171340  LV3 2021年1月11日
最近浏览更多
cz8857216  LV4 3月8日
shuangfu  LV24 2023年12月2日
镜影  LV3 2023年9月14日
Eddie233  LV5 2023年6月14日
可是不知道么  LV23 2023年5月6日
Demo1111  LV30 2023年4月23日
a1w4fsdaf  LV9 2023年4月7日
173745830  LV11 2023年2月1日
微信网友_6145740972576768  LV2 2022年12月21日
Sean_admin  LV7 2022年9月8日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友