mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
Closed https://github.com/cskefu/cskefu/issues/835 use HikariDataSource for mysql connection management
This commit is contained in:
parent
9a1038bede
commit
e0992e162a
@ -37,7 +37,7 @@ docker build --build-arg VCS_REF=$PACKAGE_VERSION \
|
|||||||
--force-rm=true --tag $registryPrefix$imagename:$PACKAGE_VERSION .
|
--force-rm=true --tag $registryPrefix$imagename:$PACKAGE_VERSION .
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
docker tag $registryPrefix$imagename:$PACKAGE_VERSION $registryPrefix$imagename:develop
|
docker tag $registryPrefix$imagename:$PACKAGE_VERSION $registryPrefix$imagename:v7
|
||||||
else
|
else
|
||||||
echo "Build contact-center failure."
|
echo "Build contact-center failure."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -22,4 +22,4 @@ if [ -d ../private ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
docker push $registryPrefix$imagename:$PACKAGE_VERSION
|
docker push $registryPrefix$imagename:$PACKAGE_VERSION
|
||||||
docker push $registryPrefix$imagename:develop
|
docker push $registryPrefix$imagename:v7
|
@ -91,7 +91,7 @@ public class Application {
|
|||||||
System.out.println(">> 春松客服采用开源许可证:Apache License 2.0");
|
System.out.println(">> 春松客服采用开源许可证:Apache License 2.0");
|
||||||
System.out.println(">> 详细介绍:https://www.cskefu.com/cskefu-opensource-license");
|
System.out.println(">> 详细介绍:https://www.cskefu.com/cskefu-opensource-license");
|
||||||
System.out.println(">> CSKeFu is released under Apache License 2.0");
|
System.out.println(">> CSKeFu is released under Apache License 2.0");
|
||||||
System.out.println(">> Get details about CSKeFu License with https://www.cskefu.com/cskefu-opensource-license");
|
System.out.println(">> NOTICE: CSKeFu v8 is released on Jun. 2023, switch to v8 to gain more outcome. CSKeFu v7 is sunset since then.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 优客服-多渠道客服系统
|
|
||||||
* Modifications copyright (C) 2018-2022 Chatopera Inc, <https://www.chatopera.com>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.cskefu.cc.config;
|
|
||||||
|
|
||||||
import com.alibaba.druid.support.http.StatViewServlet;
|
|
||||||
import com.alibaba.druid.support.http.WebStatFilter;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnClass(com.alibaba.druid.pool.DruidDataSource.class)
|
|
||||||
@ConditionalOnProperty(name = "spring.datasource.type", havingValue = "com.alibaba.druid.pool.DruidDataSource", matchIfMissing = true)
|
|
||||||
public class DruidConfiguration {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected <T> T createDataSource(DataSourceProperties properties,
|
|
||||||
Class<? extends DataSource> type) {
|
|
||||||
return (T) properties.initializeDataSourceBuilder().type(type).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.Tomcat 仿写的你可以去了解
|
|
||||||
* @param properties 读入的配置
|
|
||||||
* @return DruidDataSource
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@ConfigurationProperties("spring.datasource.druid")
|
|
||||||
public com.alibaba.druid.pool.DruidDataSource dataSource(DataSourceProperties properties) {
|
|
||||||
|
|
||||||
com.alibaba.druid.pool.DruidDataSource dataSource = createDataSource(properties, com.alibaba.druid.pool.DruidDataSource.class);
|
|
||||||
|
|
||||||
DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(properties.determineUrl());
|
|
||||||
|
|
||||||
String validationQuery = databaseDriver.getValidationQuery();
|
|
||||||
if (validationQuery != null) {
|
|
||||||
dataSource.setTestOnBorrow(true);
|
|
||||||
dataSource.setValidationQuery(validationQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册一个StatViewServlet
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public ServletRegistrationBean DruidStatViewServle2(){
|
|
||||||
//org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册.
|
|
||||||
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
|
|
||||||
//添加初始化参数:initParams
|
|
||||||
//白名单:
|
|
||||||
// servletRegistrationBean.addInitParameter("allow","127.0.0.1");
|
|
||||||
//IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
|
|
||||||
// servletRegistrationBean.addInitParameter("deny","192.168.1.73");
|
|
||||||
//登录查看信息的账号密码.
|
|
||||||
servletRegistrationBean.addInitParameter("loginUsername","admin");
|
|
||||||
servletRegistrationBean.addInitParameter("loginPassword","123456");
|
|
||||||
//是否能够重置数据.
|
|
||||||
servletRegistrationBean.addInitParameter("resetEnable","false");
|
|
||||||
return servletRegistrationBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册一个:filterRegistrationBean
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public FilterRegistrationBean druidStatFilter2(){
|
|
||||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
|
|
||||||
//添加过滤规则.
|
|
||||||
filterRegistrationBean.addUrlPatterns("/*");
|
|
||||||
//添加不需要忽略的格式信息.
|
|
||||||
filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid2/*");
|
|
||||||
return filterRegistrationBean;
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,17 +16,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.cskefu.cc.persistence.repository;
|
package com.cskefu.cc.persistence.repository;
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import mondrian.olap.Connection;
|
import mondrian.olap.Connection;
|
||||||
import mondrian.olap.DriverManager;
|
import mondrian.olap.DriverManager;
|
||||||
import mondrian.olap.Util;
|
import mondrian.olap.Util;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DataSourceService {
|
public class DataSourceService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DruidDataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param xml
|
* @param xml
|
||||||
|
@ -89,44 +89,22 @@ spring.data.elasticsearch.repositories.enabled=true
|
|||||||
|
|
||||||
spring.data.elasticsearch.properties.index.max_result_window=100000
|
spring.data.elasticsearch.properties.index.max_result_window=100000
|
||||||
|
|
||||||
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
|
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
|
||||||
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/cosinee?useUnicode=true&characterEncoding=UTF-8
|
spring.datasource.url=jdbc:mysql://localhost:3306/cosinee?useUnicode=true&characterEncoding=UTF-8
|
||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
spring.datasource.password=123456
|
spring.datasource.password=123456
|
||||||
|
# More about params of hikari https://stackoverflow.com/questions/26490967/how-do-i-configure-hikaricp-in-my-spring-boot-app-in-my-application-properties-f
|
||||||
|
spring.datasource.hikari.idle-timeout=10000
|
||||||
|
spring.datasource.hikari.maximum-pool-size=30
|
||||||
|
spring.datasource.hikari.minimum-idle=10
|
||||||
|
spring.datasource.hikari.connection-timeout=250
|
||||||
|
|
||||||
# MySQL Blob
|
# MySQL Blob
|
||||||
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
|
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
|
||||||
spring.jpa.show-sql=false
|
spring.jpa.show-sql=false
|
||||||
spring.jpa.properties.hibernate.format_sql=true
|
spring.jpa.properties.hibernate.format_sql=true
|
||||||
|
|
||||||
##Druid
|
|
||||||
# \u521D\u59CB\u5316\u5927\u5C0F\uFF0C\u6700\u5C0F\uFF0C\u6700\u5927
|
|
||||||
spring.datasource.druid.initial-size=5
|
|
||||||
spring.datasource.druid.max-active=100
|
|
||||||
spring.datasource.druid.min-idle=5
|
|
||||||
# \u914D\u7F6E\u83B7\u53D6\u8FDE\u63A5\u7B49\u5F85\u8D85\u65F6\u7684\u65F6\u95F4
|
|
||||||
spring.datasource.druid.max-wait=60000
|
|
||||||
# \u6253\u5F00PSCache\uFF0C\u5E76\u4E14\u6307\u5B9A\u6BCF\u4E2A\u8FDE\u63A5\u4E0APSCache\u7684\u5927\u5C0F
|
|
||||||
spring.datasource.druid.pool-prepared-statements=true
|
|
||||||
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
|
|
||||||
#spring.datasource.druid.max-open-prepared-statements= #\u548C\u4E0A\u9762\u7684\u7B49\u4EF7
|
|
||||||
spring.datasource.druid.validation-query=SELECT 1 FROM DUAL
|
|
||||||
spring.datasource.druid.validation-query-timeout=60000
|
|
||||||
spring.datasource.druid.test-on-borrow=false
|
|
||||||
spring.datasource.druid.test-on-return=false
|
|
||||||
spring.datasource.druid.test-while-idle=true
|
|
||||||
# \u914D\u7F6E\u95F4\u9694\u591A\u4E45\u624D\u8FDB\u884C\u4E00\u6B21\u68C0\u6D4B\uFF0C\u68C0\u6D4B\u9700\u8981\u5173\u95ED\u7684\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2
|
|
||||||
spring.datasource.druid.time-between-eviction-runs-millis=60000
|
|
||||||
# \u914D\u7F6E\u4E00\u4E2A\u8FDE\u63A5\u5728\u6C60\u4E2D\u6700\u5C0F\u751F\u5B58\u7684\u65F6\u95F4\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2
|
|
||||||
spring.datasource.druid.min-evictable-idle-time-millis=100000
|
|
||||||
# \u914D\u7F6E\u4E00\u4E2A\u8FDE\u63A5\u5728\u6C60\u4E2D\u6700\u5927\u751F\u5B58\u7684\u65F6\u95F4\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2
|
|
||||||
#spring.datasource.druid.max-evictable-idle-time-millis=
|
|
||||||
spring.datasource.druid.filters=stat,wall,log4j
|
|
||||||
# WebStatFilter\u914D\u7F6E\uFF0C\u8BF4\u660E\u8BF7\u53C2\u8003Druid Wiki\uFF0C\u914D\u7F6E_\u914D\u7F6EWebStatFilter
|
|
||||||
spring.datasource.druid.web-stat-filter.enabled=true
|
|
||||||
spring.datasource.druid.web-stat-filter.url-pattern=/*
|
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Cache
|
# Cache
|
||||||
##############################################
|
##############################################
|
||||||
|
@ -107,6 +107,18 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.apache.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-jdbc</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://www.baeldung.com/spring-boot-hikari -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.zaxxer</groupId>
|
||||||
|
<artifactId>HikariCP</artifactId>
|
||||||
|
<version>4.0.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -224,12 +236,6 @@
|
|||||||
<version>1.9.4</version>
|
<version>1.9.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba</groupId>
|
|
||||||
<artifactId>druid</artifactId>
|
|
||||||
<version>1.0.27</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.lionsoul</groupId>
|
<groupId>org.lionsoul</groupId>
|
||||||
<artifactId>ip2region</artifactId>
|
<artifactId>ip2region</artifactId>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user