From d10455715342f8107a38cda0b29a79547339fe27 Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Mon, 9 Aug 2021 11:39:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=95=86=E5=9F=8E):=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- waynboot-admin-api/pom.xml | 24 +++-- .../admin/framework/config/DruidConfig.java | 2 +- .../filter/JwtAuthenticationTokenFilter.java | 2 +- .../src/main/resources/application-druid.yml | 42 +++++++++ .../src/main/resources/application.yml | 4 +- waynboot-common/pom.xml | 7 -- .../common/core/mapper/shop/GoodsMapper.java | 2 +- .../core/service/shop/IGoodsService.java | 9 +- .../service/shop/impl/GoodsServiceImpl.java | 4 +- .../src/main/resources/application-dev.yml | 68 ++++---------- .../resources/mapper/shop/GoodsMapper.xml | 10 +-- .../concretestrategy/ColumnStrategy.java | 8 +- .../mobile/framework/config/DruidConfig.java | 71 --------------- .../framework/config/HikariCpConfig.java | 17 ++++ .../config/properties/DruidProperties.java | 69 --------------- .../config/properties/HikariProperties.java | 88 +++++++++++++++++++ .../src/main/resources/application-hikari.yml | 22 +++++ .../src/main/resources/application.yml | 2 +- 18 files changed, 219 insertions(+), 232 deletions(-) create mode 100644 waynboot-admin-api/src/main/resources/application-druid.yml delete mode 100644 waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/DruidConfig.java create mode 100644 waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/HikariCpConfig.java delete mode 100644 waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/DruidProperties.java create mode 100644 waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/HikariProperties.java create mode 100644 waynboot-mobile-api/src/main/resources/application-hikari.yml diff --git a/waynboot-admin-api/pom.xml b/waynboot-admin-api/pom.xml index eb8d6a6..5baa92c 100644 --- a/waynboot-admin-api/pom.xml +++ b/waynboot-admin-api/pom.xml @@ -17,6 +17,14 @@ + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + org.elasticsearch.client elasticsearch-rest-high-level-client @@ -95,9 +103,9 @@ com.wayn.AdminApplication ZIP - - - + + + @@ -108,16 +116,16 @@ - + + <!–配置基本镜像–> ${docker-from-image-name} - + <!–配置最终推送的地址,仓库名,镜像名–> registry.cn-shanghai.aliyuncs.com/${aliyun-docker-namespace}/${project.artifactId} @@ -142,7 +150,7 @@ - + <!– 绑定到maven lifecicle–> package @@ -151,7 +159,7 @@ - + --> diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/framework/config/DruidConfig.java b/waynboot-admin-api/src/main/java/com/wayn/admin/framework/config/DruidConfig.java index f8d23ff..01793eb 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/framework/config/DruidConfig.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/framework/config/DruidConfig.java @@ -20,7 +20,7 @@ public class DruidConfig { @Bean - @ConfigurationProperties("spring.datasource.druid.master") + @ConfigurationProperties("spring.datasource.master") public DataSource dataSource(DruidProperties druidProperties) { DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); return druidProperties.dataSource(dataSource); diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/filter/JwtAuthenticationTokenFilter.java b/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/filter/JwtAuthenticationTokenFilter.java index e861e56..62ba6d3 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/filter/JwtAuthenticationTokenFilter.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/framework/security/filter/JwtAuthenticationTokenFilter.java @@ -44,7 +44,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { SecurityContextHolder.getContext().setAuthentication(authenticationToken); } chain.doFilter(request, response); - } catch (RedisConnectionFailureException exception) { + } catch (RedisConnectionFailureException exception) { // 处理redis连接超时异常 response.setStatus(HttpStatus.OK.value()); response.setContentType("application/json"); response.setCharacterEncoding(Constants.UTF_ENCODING); diff --git a/waynboot-admin-api/src/main/resources/application-druid.yml b/waynboot-admin-api/src/main/resources/application-druid.yml new file mode 100644 index 0000000..fd68e79 --- /dev/null +++ b/waynboot-admin-api/src/main/resources/application-druid.yml @@ -0,0 +1,42 @@ +# druid数据源配置 +spring: + datasource: + druid: + initialSize: 10 + # 最小连接池数量 + minIdle: 10 + # 最大连接池数量 + maxActive: 50 + # 配置获取连接等待超时的时间 + # maxWait: 60000 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + timeBetweenEvictionRunsMillis: 60000 + # 配置一个连接在池中最小生存的时间,单位是毫秒 + minEvictableIdleTimeMillis: 300000 + # 配置一个连接在池中最大生存的时间,单位是毫秒 + maxEvictableIdleTimeMillis: 900000 + # 配置检测连接是否有效 + validationQuery: SELECT 1 + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + webStatFilter: + enabled: true + statViewServlet: + enabled: true + # 设置白名单,不填则允许所有访问 + allow: + url-pattern: /druid/* + # 控制台管理用户名和密码 + login-username: + login-password: + filter: + stat: + enabled: true + # 慢SQL记录 + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true diff --git a/waynboot-admin-api/src/main/resources/application.yml b/waynboot-admin-api/src/main/resources/application.yml index b9a52d7..03560b3 100644 --- a/waynboot-admin-api/src/main/resources/application.yml +++ b/waynboot-admin-api/src/main/resources/application.yml @@ -3,7 +3,7 @@ server: spring: profiles: - active: dev + active: dev,druid thymeleaf: cache: false suffix: .html @@ -52,7 +52,7 @@ wayn: name: wayn version: 1.1.0 email: 166738430@qq.com -# uploadDir: /opt/wayn/upload # linux下文件上传目录 +·# uploadDir: /opt/wayn/upload # linux下文件上传目录 uploadDir: D:/wayn/upload # windows下文件上传目录 adminUrl: http://127.0.0.1:81 mobileUrl: http://127.0.0.1:82 diff --git a/waynboot-common/pom.xml b/waynboot-common/pom.xml index 1c1ad98..26a1607 100644 --- a/waynboot-common/pom.xml +++ b/waynboot-common/pom.xml @@ -61,13 +61,6 @@ ${mybatis-plus.version} - - - com.alibaba - druid-spring-boot-starter - ${druid.version} - - mysql mysql-connector-java diff --git a/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java b/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java index 69a36e4..e7cf854 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java @@ -30,5 +30,5 @@ public interface GoodsMapper extends BaseMapper { List selectHomeIndex(Goods goods); - IPage selectColumnGoodsPage(Page page, List goodsIdList); + IPage selectColumnGoodsPage(Page page, Long columnId); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java index c8f5889..20dfeae 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java @@ -95,5 +95,12 @@ public interface IGoodsService extends IService { List searchResult(Page page, SearchVO searchVO); - IPage selectColumnGoodsPage(Page page, List goodsIdList); + /** + * 根据栏目ID查询栏目下商品 + * + * @param page 分页参数 + * @param columnId 栏目ID + * @return 分页对象 + */ + IPage selectColumnGoodsPageByColumnId(Page page, Long columnId); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java index c9903f9..c97b130 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java @@ -237,8 +237,8 @@ public class GoodsServiceImpl extends ServiceImpl implements } @Override - public IPage selectColumnGoodsPage(Page page, List goodsIdList) { - return goodsMapper.selectColumnGoodsPage(page, goodsIdList); + public IPage selectColumnGoodsPageByColumnId(Page page, Long columnId) { + return goodsMapper.selectColumnGoodsPage(page, columnId); } /** diff --git a/waynboot-common/src/main/resources/application-dev.yml b/waynboot-common/src/main/resources/application-dev.yml index c15bfeb..5a3e3db 100644 --- a/waynboot-common/src/main/resources/application-dev.yml +++ b/waynboot-common/src/main/resources/application-dev.yml @@ -1,60 +1,20 @@ # 数据源配置 spring: datasource: - type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver - druid: - # 主库数据源 - master: - url: jdbc:mysql://127.0.0.1:3306/wayn_shop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root - password: 123456 - # 从库数据源 - slave: - # 从数据源开关/默认关闭 - enabled: false - url: - username: - password: - # 初始连接数 - initialSize: 40 - # 最小连接池数量 - minIdle: 40 - # 最大连接池数量 - maxActive: 60 - # 配置获取连接等待超时的时间 - maxWait: 60000 - # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 - timeBetweenEvictionRunsMillis: 60000 - # 配置一个连接在池中最小生存的时间,单位是毫秒 - minEvictableIdleTimeMillis: 300000 - # 配置一个连接在池中最大生存的时间,单位是毫秒 - maxEvictableIdleTimeMillis: 900000 - # 配置检测连接是否有效 - validationQuery: SELECT 1 FROM DUAL - testWhileIdle: true - testOnBorrow: false - testOnReturn: false - webStatFilter: - enabled: true - statViewServlet: - enabled: true - # 设置白名单,不填则允许所有访问 - allow: - url-pattern: /druid/* - # 控制台管理用户名和密码 - login-username: - login-password: - filter: - stat: - enabled: true - # 慢SQL记录 - log-slow-sql: true - slow-sql-millis: 1000 - merge-sql: true - wall: - config: - multi-statement-allow: true + # 主库数据源 + master: + url: jdbc:mysql://127.0.0.1:3306/wayn_shop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: root + # 从库数据源 + slave: + # 从数据源开关/默认关闭 + enabled: false + url: + username: + password: + redis: host: 127.0.0.1 port: 6379 @@ -86,6 +46,8 @@ es: host: huawei.wayn.ltd port: 9200 scheme: http + shards: 3 + replicas: 2 # alipay 需要自行申请支付宝的沙箱账号、申请appID,并依次配置AppID、密钥、公钥,否则无法发起支付宝支付。 alipay: diff --git a/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml b/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml index d797c35..2701f42 100644 --- a/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml +++ b/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml @@ -165,14 +165,8 @@ del_flag = 0 - and is_on_sale = 1 - - and id in ( - - #{item} - - ) - + AND is_on_sale = 1 + AND id in ( SELECT goods_id FROM shop_column_goods_relation r WHERE r.column_id = #{columnId} ) order by create_time desc diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/design/strategy/concretestrategy/ColumnStrategy.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/design/strategy/concretestrategy/ColumnStrategy.java index f987fcb..17fab74 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/design/strategy/concretestrategy/ColumnStrategy.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/design/strategy/concretestrategy/ColumnStrategy.java @@ -1,8 +1,6 @@ package com.wayn.mobile.design.strategy.concretestrategy; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.wayn.common.core.domain.shop.ColumnGoodsRelation; import com.wayn.common.core.domain.shop.Diamond; import com.wayn.common.core.domain.shop.Goods; import com.wayn.common.core.service.shop.IColumnGoodsRelationService; @@ -13,7 +11,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; -import java.util.stream.Collectors; /** * 栏目跳转策略 @@ -29,10 +26,7 @@ public class ColumnStrategy implements DiamondJumpType { @Override public List getGoods(Page page, Diamond diamond) { - List goodsRelationList = iColumnGoodsRelationService - .list(new QueryWrapper().eq("column_id", diamond.getValueId())); - List goodsIdList = goodsRelationList.stream().map(ColumnGoodsRelation::getGoodsId).collect(Collectors.toList()); - return iGoodsService.selectColumnGoodsPage(page, goodsIdList).getRecords(); + return iGoodsService.selectColumnGoodsPageByColumnId(page, diamond.getValueId()).getRecords(); } @Override diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/DruidConfig.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/DruidConfig.java deleted file mode 100644 index 542f0d5..0000000 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/DruidConfig.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.wayn.mobile.framework.config; - -import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; -import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; -import com.alibaba.druid.util.Utils; -import com.wayn.mobile.framework.config.properties.DruidProperties; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.servlet.*; -import javax.sql.DataSource; -import java.io.IOException; - -@Configuration -public class DruidConfig { - - - @Bean - @ConfigurationProperties("spring.datasource.druid.master") - public DataSource dataSource(DruidProperties druidProperties) { - DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); - return druidProperties.dataSource(dataSource); - } - - /** - * 去除监控页面底部的广告 - */ - @SuppressWarnings({"rawtypes", "unchecked"}) - @Bean - @ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true") - public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) { - // 获取web监控页面的参数 - DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); - // 提取common.js的配置路径 - String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; - String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); - final String filePath = "support/http/resources/js/common.js"; - // 创建filter进行过滤 - Filter filter = new Filter() { - @Override - public void init(FilterConfig filterConfig) { - } - - @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) - throws IOException, ServletException { - chain.doFilter(request, response); - // 重置缓冲区,响应头不会被重置 - response.resetBuffer(); - // 获取common.js - String text = Utils.readFromResource(filePath); - // 正则替换banner, 除去底部的广告信息 - text = text.replaceAll("
", ""); - text = text.replaceAll("powered.*?shrek.wang", ""); - response.getWriter().write(text); - } - - @Override - public void destroy() { - } - }; - FilterRegistrationBean registrationBean = new FilterRegistrationBean(); - registrationBean.setFilter(filter); - registrationBean.addUrlPatterns(commonJsPattern); - return registrationBean; - } -} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/HikariCpConfig.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/HikariCpConfig.java new file mode 100644 index 0000000..c81f473 --- /dev/null +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/HikariCpConfig.java @@ -0,0 +1,17 @@ +package com.wayn.mobile.framework.config; + +import com.wayn.mobile.framework.config.properties.HikariProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.sql.DataSource; + +@Configuration +public class HikariCpConfig { + + + @Bean + public DataSource dataSource(HikariProperties hikariProperties) { + return hikariProperties.dataSource(); + } +} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/DruidProperties.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/DruidProperties.java deleted file mode 100644 index 5d31c8f..0000000 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/DruidProperties.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.wayn.mobile.framework.config.properties; - -import com.alibaba.druid.pool.DruidDataSource; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; - -/** - * druid 配置属性 - * - * @author ruoyi - */ -@Configuration -public class DruidProperties { - @Value("${spring.datasource.druid.initialSize}") - private int initialSize; - - @Value("${spring.datasource.druid.minIdle}") - private int minIdle; - - @Value("${spring.datasource.druid.maxActive}") - private int maxActive; - - @Value("${spring.datasource.druid.timeBetweenEvictionRunsMillis}") - private int timeBetweenEvictionRunsMillis; - - @Value("${spring.datasource.druid.minEvictableIdleTimeMillis}") - private int minEvictableIdleTimeMillis; - - @Value("${spring.datasource.druid.maxEvictableIdleTimeMillis}") - private int maxEvictableIdleTimeMillis; - - @Value("${spring.datasource.druid.validationQuery}") - private String validationQuery; - - @Value("${spring.datasource.druid.testWhileIdle}") - private boolean testWhileIdle; - - @Value("${spring.datasource.druid.testOnBorrow}") - private boolean testOnBorrow; - - @Value("${spring.datasource.druid.testOnReturn}") - private boolean testOnReturn; - - public DruidDataSource dataSource(DruidDataSource datasource) { - /** 配置初始化大小、最小、最大 */ - datasource.setInitialSize(initialSize); - datasource.setMaxActive(maxActive); - datasource.setMinIdle(minIdle); - - /** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */ - datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); - - /** 配置一个连接在池中最小、最大生存的时间,单位是毫秒 */ - datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); - datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); - - /** - * 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。 - */ - datasource.setValidationQuery(validationQuery); - /** 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 */ - datasource.setTestWhileIdle(testWhileIdle); - /** 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ - datasource.setTestOnBorrow(testOnBorrow); - /** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ - datasource.setTestOnReturn(testOnReturn); - return datasource; - } -} diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/HikariProperties.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/HikariProperties.java new file mode 100644 index 0000000..07d39c7 --- /dev/null +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/properties/HikariProperties.java @@ -0,0 +1,88 @@ +package com.wayn.mobile.framework.config.properties; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class HikariProperties { + + @Value("${spring.datasource.master.url}") + private String jdbcUrl; + @Value("${spring.datasource.master.username}") + private String username; + @Value("${spring.datasource.master.password}") + private String password; + + + @Value("${spring.datasource.hikari.poolName}") + private String poolName; + + @Value("${spring.datasource.hikari.minimumIdle}") + private int minimumIdle; + + @Value("${spring.datasource.hikari.maximumPoolSize}") + private int maximumPoolSize; + + @Value("${spring.datasource.hikari.autoCommit}") + private boolean autoCommit; + + @Value("${spring.datasource.hikari.idleTimeout}") + private int idleTimeout; + + @Value("${spring.datasource.hikari.maxLifetime}") + private int maxLifetime; + + @Value("${spring.datasource.hikari.connectionTimeout}") + private int connectionTimeout; + + @Value("${spring.datasource.hikari.connectionTestQuery}") + private String connectionTestQuery; + + @Value("${spring.datasource.hikari.cachePrepStmts}") + private boolean cachePrepStmts; + @Value("${spring.datasource.hikari.prepStmtCacheSize}") + private int prepStmtCacheSize; + @Value("${spring.datasource.hikari.prepStmtCacheSqlLimit}") + private int prepStmtCacheSqlLimit; + @Value("${spring.datasource.hikari.useServerPrepStmts}") + private boolean useServerPrepStmts; + @Value("${spring.datasource.hikari.useLocalSessionState}") + private boolean useLocalSessionState; + @Value("${spring.datasource.hikari.rewriteBatchedStatements}") + private boolean rewriteBatchedStatements; + @Value("${spring.datasource.hikari.cacheResultSetMetadata}") + private boolean cacheResultSetMetadata; + @Value("${spring.datasource.hikari.elideSetAutoCommits}") + private boolean elideSetAutoCommits; + @Value("${spring.datasource.hikari.maintainTimeStats}") + private boolean maintainTimeStats; + + public HikariDataSource dataSource() { + HikariConfig config = new HikariConfig(); + config.setJdbcUrl(jdbcUrl); + config.setUsername(username); + config.setPassword(password); + + config.setPoolName(poolName); + config.setMinimumIdle(minimumIdle); + config.setMaximumPoolSize(maximumPoolSize); + config.setAutoCommit(autoCommit); + config.setIdleTimeout(idleTimeout); + config.setMaxLifetime(maxLifetime); + config.setConnectionTimeout(connectionTimeout); + config.setConnectionTestQuery(connectionTestQuery); + config.addDataSourceProperty("cachePrepStmts", cachePrepStmts); + config.addDataSourceProperty("prepStmtCacheSize", prepStmtCacheSize); + config.addDataSourceProperty("prepStmtCacheSqlLimit", prepStmtCacheSqlLimit); + config.addDataSourceProperty("useServerPrepStmts", useServerPrepStmts); + config.addDataSourceProperty("useLocalSessionState", useLocalSessionState); + config.addDataSourceProperty("rewriteBatchedStatements", rewriteBatchedStatements); + config.addDataSourceProperty("cacheResultSetMetadata", cacheResultSetMetadata); + config.addDataSourceProperty("elideSetAutoCommits", elideSetAutoCommits); + config.addDataSourceProperty("maintainTimeStats", maintainTimeStats); + + return new HikariDataSource(config); + } +} diff --git a/waynboot-mobile-api/src/main/resources/application-hikari.yml b/waynboot-mobile-api/src/main/resources/application-hikari.yml new file mode 100644 index 0000000..04d91e7 --- /dev/null +++ b/waynboot-mobile-api/src/main/resources/application-hikari.yml @@ -0,0 +1,22 @@ +# hikari数据源配置 +spring: + datasource: + hikari: + poolName: hikariCP + minimumIdle: 10 + maximumPoolSize: 50 + autoCommit: true + idleTimeout: 10000 + maxLifetime: 30000 + connectionTimeout: 30000 + connectionTestQuery: SELECT 1 + cachePrepStmts: true + prepStmtCacheSize: 250 + prepStmtCacheSqlLimit: 2048 + useServerPrepStmts: true + useLocalSessionState: true + rewriteBatchedStatements: true + cacheResultSetMetadata: true + cacheServerConfiguration: true + elideSetAutoCommits: true + maintainTimeStats: false diff --git a/waynboot-mobile-api/src/main/resources/application.yml b/waynboot-mobile-api/src/main/resources/application.yml index e6a3ccb..eab20df 100644 --- a/waynboot-mobile-api/src/main/resources/application.yml +++ b/waynboot-mobile-api/src/main/resources/application.yml @@ -11,7 +11,7 @@ server: spring: profiles: - active: dev + active: dev,hikari thymeleaf: cache: false suffix: .html