|
@@ -1,10 +1,13 @@
|
|
|
package cn.hnthyy.thmz.common.datasource;
|
|
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource;
|
|
|
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
-import org.mybatis.spring.SqlSessionFactoryBean;
|
|
|
import org.mybatis.spring.SqlSessionTemplate;
|
|
|
import org.mybatis.spring.annotation.MapperScan;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
@@ -12,12 +15,13 @@ import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
+
|
|
|
import javax.sql.DataSource;
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
@Configuration
|
|
|
@MapperScan(basePackages = "cn.hnthyy.thmz.mapper.his", sqlSessionTemplateRef = "hisSqlSessionTemplate")
|
|
|
-public class DruidHisDataSource {
|
|
|
+public class DruidHisDataSource extends BaseDataSource{
|
|
|
@Value("${spring.datasource.his.driver-class-name}")
|
|
|
private String driverClassName;
|
|
|
@Value("${spring.datasource.his.jdbc-url}")
|
|
@@ -26,43 +30,9 @@ public class DruidHisDataSource {
|
|
|
private String username;
|
|
|
@Value("${spring.datasource.his.password}")
|
|
|
private String password;
|
|
|
+ @Autowired
|
|
|
+ private MybatisPlusInterceptor sqlSeverMybatisPlusInterceptor;
|
|
|
|
|
|
-// @Value("${spring.datasource.durid.type}")
|
|
|
-// private Class type;
|
|
|
- @Value("${spring.datasource.durid.initial-size}")
|
|
|
- private Integer initialSize;
|
|
|
- @Value("${spring.datasource.durid.max-active}")
|
|
|
- private Integer maxActive;
|
|
|
- @Value("${spring.datasource.durid.min-idle}")
|
|
|
- private Integer minIdle;
|
|
|
- @Value("${spring.datasource.durid.max-wait}")
|
|
|
- private Long maxWait;
|
|
|
- @Value("${spring.datasource.durid.validation-query}")
|
|
|
- private String validationQuery;
|
|
|
- @Value("${spring.datasource.durid.test-while-idle}")
|
|
|
- private Boolean testWhileIdle;
|
|
|
- @Value("${spring.datasource.durid.test-on-borrow}")
|
|
|
- private Boolean testOnBorrow;
|
|
|
- @Value("${spring.datasource.durid.test-on-return}")
|
|
|
- private Boolean testOnReturn;
|
|
|
- @Value("${spring.datasource.durid.time-between-eviction-runs-millis}")
|
|
|
- private Long timeBetweenEvictionRunsMillis;
|
|
|
- @Value("${spring.datasource.durid.min-evictable-idle-time-millis}")
|
|
|
- private Long minEvictableIdleTimeMillis;
|
|
|
- @Value("${spring.datasource.durid.filters}")
|
|
|
- private String filters;
|
|
|
- @Value("${spring.datasource.durid.pool-prepared-statements}")
|
|
|
- private Boolean poolPreparedStatements;
|
|
|
- @Value("${spring.datasource.durid.max-pool-prepared-statement-per-connection-size}")
|
|
|
- private Integer maxPoolPreparedStatementPerConnectionSize;
|
|
|
- @Value("${spring.datasource.durid.remove-abandoned}")
|
|
|
- private Boolean removeAbandoned;
|
|
|
- @Value("${spring.datasource.durid.remove-abandoned-timeout}")
|
|
|
- private Integer removeAbandonedTimeout;
|
|
|
- @Value("${spring.datasource.durid.log-abandoned}")
|
|
|
- private Boolean logAbandoned;
|
|
|
- @Value("${spring.datasource.durid.use-unfair-lock}")
|
|
|
- private Boolean useUnfairLock;
|
|
|
/**
|
|
|
* 多数据源工程,这是导致这个配置没有生效的原因,因为他不知道为哪个数据源开启驼峰命名
|
|
|
* 所以我们需要在配置多数据源的文件中,单独加入配置,(其他配置也是如此,只要涉及到多数据源的,都需要给每一个数据源去配置)
|
|
@@ -70,10 +40,10 @@ public class DruidHisDataSource {
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean(name = "hisConfiguration")
|
|
|
- @ConfigurationProperties(prefix = "mybatis.configuration")
|
|
|
+ @ConfigurationProperties(prefix = "mybatis-plus.configuration")
|
|
|
@Primary
|
|
|
- public org.apache.ibatis.session.Configuration hisConfiguration() {
|
|
|
- return new org.apache.ibatis.session.Configuration();
|
|
|
+ public MybatisConfiguration hisConfiguration() {
|
|
|
+ return new MybatisConfiguration();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -114,10 +84,12 @@ public class DruidHisDataSource {
|
|
|
|
|
|
@Bean(name = "hisSqlSessionFactory")
|
|
|
@Primary
|
|
|
- public SqlSessionFactory hisSqlSessionFactory(@Qualifier("hisData") DataSource dataSource, @Qualifier("hisConfiguration") org.apache.ibatis.session.Configuration configuration) throws Exception {
|
|
|
- SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
|
|
+ public SqlSessionFactory hisSqlSessionFactory(@Qualifier("hisData") DataSource dataSource, @Qualifier("hisConfiguration") MybatisConfiguration configuration) throws Exception {
|
|
|
+ //SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
|
|
+ MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
|
|
|
bean.setDataSource(dataSource);
|
|
|
bean.setConfiguration(configuration);
|
|
|
+ bean.setPlugins(sqlSeverMybatisPlusInterceptor);
|
|
|
return bean.getObject();
|
|
|
}
|
|
|
|
|
@@ -133,4 +105,6 @@ public class DruidHisDataSource {
|
|
|
return new SqlSessionTemplate(sqlSessionFactory);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|