首页>代码>spring+spring mvc+mybatis+spring boot自定义查询条件实现excel报表文件导出生成>/ygq-report/src/main/java/com/ygq/report/config/DruidConfig.java
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; // } }