更新youfool-framework-springboot 3.0的数据源配置以及使用注意事项说明
This commit is contained in:
parent
7ee9def43b
commit
f7f6a3acaa
|
|
@ -1,2 +1,8 @@
|
||||||
boot 基础模板
|
# youfool-framework-springboot 基础项目模板
|
||||||
|
|
||||||
|
## 数据源
|
||||||
|
|
||||||
|
当前版本(3.0版本以上)的基础框架使用了`苞米豆`的[动态数据源](https://github.com/baomidou/dynamic-datasource-spring-boot-starter) 。
|
||||||
|
|
||||||
|
使用事务时需注意使用`@DSTransactional`代替`@Transactional`来使用注解式事务。
|
||||||
|
|
||||||
|
|
|
||||||
2
pom.xml
2
pom.xml
|
|
@ -39,7 +39,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chinaweal.youfool</groupId>
|
<groupId>com.chinaweal.youfool</groupId>
|
||||||
<artifactId>youfool-framework-springboot</artifactId>
|
<artifactId>youfool-framework-springboot</artifactId>
|
||||||
<version>2.1.0-SNAPSHOT</version>
|
<version>3.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--postgresql-->
|
<!--postgresql-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,15 @@
|
||||||
package com.chinaweal.youfool.prj.config;
|
package com.chinaweal.youfool.prj.config;
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
|
||||||
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
||||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||||
import com.chinaweal.youfool.framework.springboot.mybatis.plus.CommonMetaObjectHandler;
|
import com.chinaweal.youfool.framework.springboot.mybatis.plus.CommonMetaObjectHandler;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
|
||||||
import org.mybatis.spring.SqlSessionTemplate;
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
@ -25,19 +19,12 @@ import javax.sql.DataSource;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@MapperScan(basePackages = {"com.chinaweal.youfool.framework.springboot.cms.**.mapper", "com.chinaweal.youfool.prj.**.mapper"}, sqlSessionTemplateRef = "prjSqlSessionTemplate")
|
@MapperScan(basePackages = {"com.chinaweal.youfool.framework.springboot.cms.**.mapper", "com.chinaweal.youfool.prj.**.mapper"})
|
||||||
public class PrjDataSource {
|
public class PrjDataSource {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CommonMetaObjectHandler commonMetaObjectHandler;
|
private CommonMetaObjectHandler commonMetaObjectHandler;
|
||||||
|
|
||||||
@Bean(name = "prjDS", initMethod = "init", destroyMethod = "close")
|
|
||||||
@ConfigurationProperties(prefix = "spring.datasource.prj")
|
|
||||||
@Primary
|
|
||||||
public DruidDataSource dataSource() {
|
|
||||||
return DruidDataSourceBuilder.create().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "prjSqlSessionFactory")
|
@Bean(name = "prjSqlSessionFactory")
|
||||||
@Primary
|
@Primary
|
||||||
public MybatisSqlSessionFactoryBean sqlSessionFactory(@Qualifier("prjDS") DataSource dataSource) throws Exception {
|
public MybatisSqlSessionFactoryBean sqlSessionFactory(@Qualifier("prjDS") DataSource dataSource) throws Exception {
|
||||||
|
|
@ -50,16 +37,4 @@ public class PrjDataSource {
|
||||||
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/mapper/**/*.xml"));
|
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mybatis/mapper/**/*.xml"));
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "prjTransactionManager")
|
|
||||||
@Primary
|
|
||||||
public DataSourceTransactionManager transactionManager(@Qualifier("prjDS") DataSource dataSource) {
|
|
||||||
return new DataSourceTransactionManager(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "prjSqlSessionTemplate")
|
|
||||||
@Primary
|
|
||||||
public SqlSessionTemplate sqlSessionTemplate(@Qualifier("prjSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
|
|
||||||
return new SqlSessionTemplate(sqlSessionFactory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,15 @@ logging:
|
||||||
com.chinaweal.youfool.prj: debug
|
com.chinaweal.youfool.prj: debug
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
prj:
|
dynamic:
|
||||||
url: jdbc:postgresql://172.22.80.157:5432/prj_template
|
datasource:
|
||||||
username: postgres
|
master:
|
||||||
password: 123456
|
url: jdbc:mysql://127.0.0.1:3306/crgs?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=UTC
|
||||||
|
username: root
|
||||||
|
password: 123456
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
|
||||||
|
youfool:
|
||||||
|
url: jdbc:mysql://127.0.0.1:3306/aiccs?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=UTC
|
||||||
|
username: root
|
||||||
|
password: 123456
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
|
|
@ -7,7 +7,15 @@ logging:
|
||||||
filePath: D:\project\pms\logs
|
filePath: D:\project\pms\logs
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
prj:
|
dynamic:
|
||||||
url: jdbc:postgresql://127.0.0.1:5432/pms
|
datasource:
|
||||||
username: postgres
|
master:
|
||||||
password: 123456
|
url: jdbc:mysql://127.0.0.1:3306/crgs?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=UTC
|
||||||
|
username: root
|
||||||
|
password: 123456
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
|
||||||
|
youfool:
|
||||||
|
url: jdbc:mysql://127.0.0.1:3306/aiccs?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=UTC
|
||||||
|
username: root
|
||||||
|
password: 123456
|
||||||
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
|
|
@ -7,17 +7,27 @@ spring:
|
||||||
application:
|
application:
|
||||||
name: youfool-prj-springboot-template
|
name: youfool-prj-springboot-template
|
||||||
datasource:
|
datasource:
|
||||||
#https://gitee.com/wenshao/druid/tree/master/druid-spring-boot-starter
|
dynamic:
|
||||||
#https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE
|
primary: master #设置默认的数据源或者数据源组,默认值即为master
|
||||||
prj:
|
strict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
|
||||||
filters: stat
|
master:
|
||||||
initial-size: 2
|
filters: stat
|
||||||
min-idle: 1
|
initial-size: 2
|
||||||
max-active: 20
|
min-idle: 1
|
||||||
max-wait: 30000
|
max-active: 20
|
||||||
time-between-eviction-runs-millis: 60000
|
max-wait: 30000
|
||||||
min-evictable-idle-time-millis: 300000
|
time-between-eviction-runs-millis: 60000
|
||||||
validation-query: select version()
|
min-evictable-idle-time-millis: 300000
|
||||||
|
validation-query: select version()
|
||||||
|
youfool: # 基础框架必要数据源,用于存储restLog
|
||||||
|
filters: stat
|
||||||
|
initial-size: 2
|
||||||
|
min-idle: 1
|
||||||
|
max-active: 20
|
||||||
|
max-wait: 30000
|
||||||
|
time-between-eviction-runs-millis: 60000
|
||||||
|
min-evictable-idle-time-millis: 300000
|
||||||
|
validation-query: select version()
|
||||||
druid:
|
druid:
|
||||||
web-stat-filter:
|
web-stat-filter:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue