Commit 8f53b91a by fsn

数据源事务失效的bug修改

parent 60b3e185
package project.config.datasource;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
import com.stylefeng.guns.core.util.ResKit;
import org.apache.ibatis.plugin.Interceptor;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource;
......@@ -22,8 +26,11 @@ import javax.sql.DataSource;
* @date 2016年11月12日 下午4:55:09
*/
@Configuration
@Import(value = DruidPoolConfig.class)
public class DataSourceConfig {
@EnableTransactionManagement
@PropertySource("classpath:jdbc.properties")
public class DataSourceConfig implements EnvironmentAware {
private Environment em;
/**
* 扫描所有mybatis的接口
......@@ -75,18 +82,6 @@ public class DataSourceConfig {
* UUID->`3`("全局唯一ID")
*/
globalConfig.setIdType(1);
/**
* MYSQL->`mysql`
* ORACLE->`oracle`
* DB2->`db2`
* H2->`h2`
* HSQL->`hsql`
* SQLITE->`sqlite`
* POSTGRE->`postgresql`
* SQLSERVER2005->`sqlserver2005`
* SQLSERVER->`sqlserver`
*/
globalConfig.setDbType("mysql");
/**
......@@ -109,4 +104,26 @@ public class DataSourceConfig {
return manager;
}
/**
* 第三方数据库连接池的配置
*
* @author fengshuonan
* @Date 2017/4/27 17:24
*/
@Bean(initMethod = "init")
public DruidDataSource dataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(em.getProperty("jdbc.url").trim());
dataSource.setUsername(em.getProperty("jdbc.username").trim());
dataSource.setPassword(em.getProperty("jdbc.password").trim());
DataSourceConfigTemplate.config(dataSource);
return dataSource;
}
@Override
public void setEnvironment(Environment environment) {
this.em = environment;
}
}
package project.config.datasource;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import java.sql.SQLException;
/**
* 第三方数据库连接池的配置
* 数据源配置模板
*
* @author fengshuonan
* @date 2016年11月12日 下午4:59:30
*/
@Configuration
@PropertySource("classpath:jdbc.properties")
public class DruidPoolConfig implements EnvironmentAware {
public class DataSourceConfigTemplate {
private Environment em;
public static void config(DruidDataSource dataSource) {
@Bean(initMethod = "init")
public DruidDataSource dataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(em.getProperty("jdbc.driver").trim());
dataSource.setInitialSize(em.getProperty("jdbc.initialSize", Integer.class));
dataSource.setMinIdle(em.getProperty("jdbc.minIdle", Integer.class));
dataSource.setMaxActive(em.getProperty("jdbc.maxActive", Integer.class));
dataSource.setMaxWait(em.getProperty("jdbc.maxWait", Long.class));
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setInitialSize(2); //定义初始连接数
dataSource.setMinIdle(1); //最小空闲
dataSource.setMaxActive(20); //定义最大连接数
dataSource.setMaxWait(60000); //最长等待时间
// 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
dataSource.setTimeBetweenEvictionRunsMillis(60000);
......@@ -50,16 +39,6 @@ public class DruidPoolConfig implements EnvironmentAware {
} catch (SQLException e) {
e.printStackTrace();
}
dataSource.setUrl(em.getProperty("jdbc.url").trim());
dataSource.setUsername(em.getProperty("jdbc.username").trim());
dataSource.setPassword(em.getProperty("jdbc.password").trim());
return dataSource;
}
@Override
public void setEnvironment(Environment environment) {
this.em = environment;
}
}
jdbc.driver=com.mysql.jdbc.Driver
# 管理系统的数据库
jdbc.url=jdbc:mysql://127.0.0.1:3306/guns?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
jdbc.username=root
jdbc.password=root
#定义初始连接数
jdbc.initialSize=2
#定义最大连接数
jdbc.maxActive=20
#定义最大空闲
jdbc.maxIdle=20
#定义最小空闲
jdbc.minIdle=1
#定义最长等待时间
jdbc.maxWait=60000
\ No newline at end of file
jdbc.password=root
\ No newline at end of file
jdbc.driver=com.mysql.jdbc.Driver
# 管理系统的数据库
jdbc.url=jdbc:mysql://127.0.0.1:3306/filco?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
jdbc.username=root
jdbc.password=root
#定义初始连接数
jdbc.initialSize=2
#定义最大连接数
jdbc.maxActive=20
#定义最大空闲
jdbc.maxIdle=20
#定义最小空闲
jdbc.minIdle=1
#定义最长等待时间
jdbc.maxWait=60000
\ No newline at end of file
jdbc.password=root
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment