feat: 添加 spring-boot-datasource starter.
This commit is contained in:
@@ -21,7 +21,9 @@
|
|||||||
<springdoc.version>1.6.15</springdoc.version>
|
<springdoc.version>1.6.15</springdoc.version>
|
||||||
<knife4j.version>4.1.0</knife4j.version>
|
<knife4j.version>4.1.0</knife4j.version>
|
||||||
<mapstruct.version>1.5.5.Final</mapstruct.version>
|
<mapstruct.version>1.5.5.Final</mapstruct.version>
|
||||||
|
<mybatis-plus.version>3.5.3.1</mybatis-plus.version>
|
||||||
|
<mybatis-plus-generator.version>3.5.3.1</mybatis-plus-generator.version>
|
||||||
|
<druid.version>1.2.16</druid.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
@@ -68,6 +70,11 @@
|
|||||||
<artifactId>orion-ops-spring-boot-starter-swagger</artifactId>
|
<artifactId>orion-ops-spring-boot-starter-swagger</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.orion.ops</groupId>
|
||||||
|
<artifactId>orion-ops-spring-boot-starter-datasource</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- spring -->
|
<!-- spring -->
|
||||||
|
|
||||||
@@ -109,6 +116,25 @@
|
|||||||
<version>${knife4j.version}</version>
|
<version>${knife4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- druid -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
<version>${druid.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
|
<version>${mybatis-plus-generator.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ public class BannerApplicationRunner implements ApplicationRunner {
|
|||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
String line = AnsiCode.GLOSS_GREEN.stain(":: orion-ops-server v" + version + " 服务已启动(" + env + ") ::\n") +
|
String line = AnsiCode.GLOSS_GREEN.stain(":: orion-ops-server v" + version + " 服务已启动(" + env + ") ::\n") +
|
||||||
AnsiCode.GLOSS_GREEN.stain(":: swagger 文档 ") +
|
AnsiCode.GLOSS_GREEN.stain(":: swagger 文档 ") +
|
||||||
// TODO swagger 地址
|
|
||||||
AnsiCode.GLOSS_BLUE.stain("http://127.0.0.1:" + port + "/doc.html\n") +
|
AnsiCode.GLOSS_BLUE.stain("http://127.0.0.1:" + port + "/doc.html\n") +
|
||||||
|
AnsiCode.GLOSS_GREEN.stain(":: druid console ") +
|
||||||
|
AnsiCode.GLOSS_BLUE.stain("http://127.0.0.1:" + port + "/druid/index.html\n") +
|
||||||
AnsiCode.GLOSS_GREEN.stain(":: server 心跳检测 ") +
|
AnsiCode.GLOSS_GREEN.stain(":: server 心跳检测 ") +
|
||||||
AnsiCode.GLOSS_BLUE +
|
AnsiCode.GLOSS_BLUE +
|
||||||
"curl -X GET --location \"http://127.0.0.1:" + port + apiPrefix + "/server/bootstrap/health\"" +
|
"curl -X GET --location \"http://127.0.0.1:" + port + apiPrefix + "/server/bootstrap/health\"" +
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<groupId>com.orion.ops</groupId>
|
||||||
|
<artifactId>orion-ops-framework</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>orion-ops-spring-boot-starter-datasource</artifactId>
|
||||||
|
<name>${project.artifactId}</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<description>项目数据源配置包</description>
|
||||||
|
<url>https://github.com/lijiahangmax/orion-ops-pro</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.orion.ops</groupId>
|
||||||
|
<artifactId>orion-ops-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mysql -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- druid -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- web -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.orion.ops.framework.datasource.config;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
||||||
|
import com.orion.ops.framework.datasource.core.filter.DruidAdRemoveFilter;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源配置类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/6/23 17:22
|
||||||
|
*/
|
||||||
|
@AutoConfiguration
|
||||||
|
@EnableTransactionManagement(proxyTargetClass = true)
|
||||||
|
@EnableConfigurationProperties(DruidStatProperties.class)
|
||||||
|
public class OrionDatasourceAutoConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return druid 数据源
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public DataSource druidDataSource() {
|
||||||
|
return new DruidDataSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param properties 配置
|
||||||
|
* @return druid 广告过滤器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "spring.datasource.druid.web-stat-filter.enabled", havingValue = "true")
|
||||||
|
public FilterRegistrationBean<DruidAdRemoveFilter> druidAdRemoveFilterFilter(DruidStatProperties properties) {
|
||||||
|
// 获取 druid web 监控页面的参数
|
||||||
|
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
|
||||||
|
// 提取 common.js 的配置路径
|
||||||
|
String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
|
||||||
|
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
||||||
|
// 创建 DruidAdRemoveFilter Bean
|
||||||
|
FilterRegistrationBean<DruidAdRemoveFilter> registrationBean = new FilterRegistrationBean<>();
|
||||||
|
registrationBean.setFilter(new DruidAdRemoveFilter());
|
||||||
|
registrationBean.addUrlPatterns(commonJsPattern);
|
||||||
|
return registrationBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.orion.ops.framework.datasource.core.filter;
|
||||||
|
|
||||||
|
import com.alibaba.druid.util.Utils;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* druid 广告过滤器
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/6/23 17:23
|
||||||
|
*/
|
||||||
|
public class DruidAdRemoveFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* common.js 的路径
|
||||||
|
*/
|
||||||
|
private static final String COMMON_JS_ILE_PATH = "support/http/resources/js/common.js";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
// 重置缓冲区 响应头不会被重置
|
||||||
|
response.resetBuffer();
|
||||||
|
// 获取 common.js
|
||||||
|
String text = Utils.readFromResource(COMMON_JS_ILE_PATH);
|
||||||
|
// 正则替换 banner 除去底部的广告信息
|
||||||
|
text = text.replaceAll("<a.*?banner\"></a><br/>", "");
|
||||||
|
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
||||||
|
response.getWriter().write(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
com.orion.ops.framework.datasource.config.OrionDatasourceAutoConfiguration
|
||||||
@@ -69,7 +69,7 @@ public class OrionWebAutoConfiguration implements WebMvcConfigurer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return http json 转换器
|
* @return http message 转换器
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
public HttpMessageConverters fastJsonHttpMessageConverters() {
|
||||||
@@ -97,15 +97,15 @@ public class OrionWebAutoConfiguration implements WebMvcConfigurer {
|
|||||||
jsonConverter.setFastJsonConfig(config);
|
jsonConverter.setFastJsonConfig(config);
|
||||||
// 先获取默认转换器
|
// 先获取默认转换器
|
||||||
List<HttpMessageConverter<?>> defaultConverters = new HttpMessageConverters().getConverters();
|
List<HttpMessageConverter<?>> defaultConverters = new HttpMessageConverters().getConverters();
|
||||||
List<HttpMessageConverter<?>> newConverters = new ArrayList<>();
|
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||||
// 将 byte converter 添加至首位 - fix swagger api 返回base64报错
|
// 将 byte converter 添加至首位 - fix swagger api 返回base64报错
|
||||||
newConverters.add(new ByteArrayHttpMessageConverter());
|
converters.add(new ByteArrayHttpMessageConverter());
|
||||||
// 添加自定义 converter - using WrapperResultHandler
|
// 添加自定义 converter - using WrapperResultHandler
|
||||||
newConverters.add(jsonConverter);
|
converters.add(jsonConverter);
|
||||||
// 添加默认 converter
|
// 添加默认 converter
|
||||||
newConverters.addAll(defaultConverters);
|
converters.addAll(defaultConverters);
|
||||||
// 设置不添加默认 converter
|
// 设置不添加默认 converter
|
||||||
return new HttpMessageConverters(false, newConverters);
|
return new HttpMessageConverters(false, converters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ public class GlobalExceptionHandler {
|
|||||||
return HttpWrapper.error(ex.getMessage());
|
return HttpWrapper.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO datasource starter
|
@ExceptionHandler(value = DataAccessResourceFailureException.class)
|
||||||
// @ExceptionHandler(value = DataAccessResourceFailureException.class)
|
|
||||||
public HttpWrapper<?> dataAccessResourceFailureExceptionHandler(HttpServletRequest request, Exception ex) {
|
public HttpWrapper<?> dataAccessResourceFailureExceptionHandler(HttpServletRequest request, Exception ex) {
|
||||||
log.error("dataAccessResourceFailureExceptionHandler url: {}, 抛出异常: {}, message: {}", request.getRequestURI(), ex.getClass(), ex.getMessage(), ex);
|
log.error("dataAccessResourceFailureExceptionHandler url: {}, 抛出异常: {}, message: {}", request.getRequestURI(), ex.getClass(), ex.getMessage(), ex);
|
||||||
return HttpWrapper.error(ExceptionMessageConst.NETWORK_FLUCTUATION);
|
return HttpWrapper.error(ExceptionMessageConst.NETWORK_FLUCTUATION);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
<module>orion-ops-spring-boot-starter-web</module>
|
<module>orion-ops-spring-boot-starter-web</module>
|
||||||
<module>orion-ops-spring-boot-starter-banner</module>
|
<module>orion-ops-spring-boot-starter-banner</module>
|
||||||
<module>orion-ops-spring-boot-starter-swagger</module>
|
<module>orion-ops-spring-boot-starter-swagger</module>
|
||||||
|
<module>orion-ops-spring-boot-starter-datasource</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -36,6 +36,10 @@
|
|||||||
<groupId>com.orion.ops</groupId>
|
<groupId>com.orion.ops</groupId>
|
||||||
<artifactId>orion-ops-spring-boot-starter-swagger</artifactId>
|
<artifactId>orion-ops-spring-boot-starter-swagger</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.orion.ops</groupId>
|
||||||
|
<artifactId>orion-ops-spring-boot-starter-datasource</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
druid:
|
||||||
|
url:
|
||||||
|
username:
|
||||||
|
password:
|
||||||
|
initial-size: 0
|
||||||
|
min-idle: 1
|
||||||
|
max-active: 5
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
druid:
|
||||||
|
url:
|
||||||
|
username:
|
||||||
|
password:
|
||||||
|
# 初始连接数
|
||||||
|
initial-size: 5
|
||||||
|
# 最小连接池数量
|
||||||
|
min-idle: 5
|
||||||
|
# 最大连接池数量
|
||||||
|
max-active: 20
|
||||||
|
web-stat-filter:
|
||||||
|
enabled: true
|
||||||
|
stat-view-servlet:
|
||||||
|
enabled: true
|
||||||
|
filter:
|
||||||
|
stat:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
enabled: false
|
||||||
|
swagger-ui:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
knife4j:
|
||||||
|
enable: false
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ spring:
|
|||||||
main:
|
main:
|
||||||
# 允许循环依赖
|
# 允许循环依赖
|
||||||
allow-circular-references: true
|
allow-circular-references: true
|
||||||
# Servlet 配置
|
|
||||||
servlet:
|
servlet:
|
||||||
# 文件上传相关配置项
|
# 文件上传相关配置项
|
||||||
multipart:
|
multipart:
|
||||||
@@ -20,6 +19,40 @@ spring:
|
|||||||
mvc:
|
mvc:
|
||||||
pathmatch:
|
pathmatch:
|
||||||
matching-strategy: ANT_PATH_MATCHER
|
matching-strategy: ANT_PATH_MATCHER
|
||||||
|
datasource:
|
||||||
|
druid:
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# 初始连接数
|
||||||
|
initial-size: 5
|
||||||
|
# 最小连接池数量
|
||||||
|
min-idle: 5
|
||||||
|
# 最大连接池数量
|
||||||
|
max-active: 20
|
||||||
|
# 配置获取连接等待超时的时间
|
||||||
|
max-wait: 600000
|
||||||
|
# 检测间隔
|
||||||
|
time-between-eviction-runs-millis: 60000
|
||||||
|
# 最小生存的时间
|
||||||
|
min-evictable-idle-time-millis: 300000
|
||||||
|
# 最大生存的时间
|
||||||
|
max-evictable-idle-time-millis: 900000
|
||||||
|
validation-query: SELECT 1
|
||||||
|
web-stat-filter:
|
||||||
|
enabled: true
|
||||||
|
stat-view-servlet:
|
||||||
|
enabled: true
|
||||||
|
url-pattern: /druid/*
|
||||||
|
login-username:
|
||||||
|
login-password:
|
||||||
|
filter:
|
||||||
|
stat:
|
||||||
|
enabled: true
|
||||||
|
log-slow-sql: true
|
||||||
|
slow-sql-millis: 800
|
||||||
|
merge-sql: true
|
||||||
|
wall:
|
||||||
|
config:
|
||||||
|
multi-statement-allow: true
|
||||||
|
|
||||||
springdoc:
|
springdoc:
|
||||||
api-docs:
|
api-docs:
|
||||||
|
|||||||
Reference in New Issue
Block a user