From f079f553f78100d82c89255def51ddfff1ddc8d1 Mon Sep 17 00:00:00 2001 From: ajaxfan <909938737@qq.com> Date: Sun, 7 Feb 2021 18:32:45 +0800 Subject: [PATCH] debug --- pom.xml | 4 +- .../BizServiceEbtpProjectApplication.java | 5 +-- .../ebtp/project/config/DataSourceConfig.java | 43 +++++++++++++++++++ src/main/resources/application-dev.yml | 33 +++----------- 4 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/project/config/DataSourceConfig.java diff --git a/pom.xml b/pom.xml index 1578513..2eeb571 100644 --- a/pom.xml +++ b/pom.xml @@ -31,12 +31,12 @@ com.chinaunicom.ebtp mall-ebtp-cloud-apollo-starter - + mysql mysql-connector-java diff --git a/src/main/java/com/chinaunicom/mall/ebtp/project/BizServiceEbtpProjectApplication.java b/src/main/java/com/chinaunicom/mall/ebtp/project/BizServiceEbtpProjectApplication.java index e2b1ea1..469627f 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/project/BizServiceEbtpProjectApplication.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/project/BizServiceEbtpProjectApplication.java @@ -8,9 +8,8 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; - -@SpringBootApplication(exclude = { DruidDataSourceAutoConfigure.class, DataSourceAutoConfiguration.class }) +//@SpringBootApplication(exclude = { DruidDataSourceAutoConfigure.class, DataSourceAutoConfiguration.class }) +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @EnableFeignClients @EnableEurekaClient @MapperScan({ "com.chinaunicom.mall.ebtp.project.**.dao" }) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/project/config/DataSourceConfig.java b/src/main/java/com/chinaunicom/mall/ebtp/project/config/DataSourceConfig.java new file mode 100644 index 0000000..c8710d4 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/project/config/DataSourceConfig.java @@ -0,0 +1,43 @@ +package com.chinaunicom.mall.ebtp.project.config; + +import javax.sql.DataSource; + +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.transaction.SpringManagedTransactionFactory; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; + +import com.alibaba.druid.pool.DruidDataSource; + +import io.seata.rm.datasource.DataSourceProxy; + +@Configuration +public class DataSourceConfig { + + @Bean + @ConfigurationProperties(prefix = "spring.datasource") + public DataSource druidDataSource() { + DruidDataSource druidDataSource = new DruidDataSource(); + return druidDataSource; + } + + @Primary + @Bean("dataSource") + public DataSourceProxy dataSource(DataSource druidDataSource){ + return new DataSourceProxy(druidDataSource); + } + + @Bean + public SqlSessionFactory sqlSessionFactory(DataSourceProxy dataSourceProxy)throws Exception{ + SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); + sqlSessionFactoryBean.setDataSource(dataSourceProxy); + sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver() + .getResources("classpath*:com/chinaunicom/mall/ebtp/**/mapper/*Mapper.xml")); + sqlSessionFactoryBean.setTransactionFactory(new SpringManagedTransactionFactory()); + return sqlSessionFactoryBean.getObject(); + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 5fec330..cfb8615 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -24,33 +24,12 @@ spring: application: name: biz-service-ebtp-project - shardingsphere: - datasource: - names: ds0 - ds0: - type: com.alibaba.druid.pool.DruidDataSource - driver-class-name: com.mysql.cj.jdbc.Driver - username: root - password: root - jdbc-url: jdbc:mysql://10.242.31.158:3033/ebtp_mall_project?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true - url: jdbc:mysql://10.242.31.158:3033/ebtp_mall_project?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true - filters: stat,wall,log4j - maxActive: 20 - initialSize: 1 - maxWait: 60000 - minIdle: 1 - timeBetweenEvictionRunsMillis: 60000 - minEvictableIdleTimeMillis: 300000 - validationQuery: select 'x' - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - poolPreparedStatements: true - maxOpenPreparedStatements: 20 - connection-properties: druid.stat.merggSql=ture;druid.stat.slowSqlMillis=5000 - props: - sql: - show: true + datasource: + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://10.242.31.158:3033/ebtp_mall_project?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true + username: root + password: root jackson: date-format: yyyy-MM-dd HH:mm:ss