From 9033ca63319186729880b8f0dd6ca2e094d8a803 Mon Sep 17 00:00:00 2001
From: xiongxiaoyang <1179705413@qq.com>
Date: Sat, 15 Mar 2025 15:06:59 +0800
Subject: [PATCH] =?UTF-8?q?build:=20Java=E7=89=88=E6=9C=AC=E5=8D=87?=
=?UTF-8?q?=E7=BA=A7=E5=88=B021=20&=20SpringBoot=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=88=B02.7.18?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config/shardingsphere-jdbc.yml | 53 +++++++
doc/sql/novel_plus.sql | 10 +-
novel-admin/pom.xml | 70 ++++-----
.../java2nb/common/aspect/WebLogAspect.java | 10 +-
.../java2nb/common/config/DruidDBConfig.java | 132 ----------------
.../java2nb/common/config/Swagger2Config.java | 48 ------
.../java2nb/common/dao/GeneratorMapper.java | 10 +-
.../exception/MainsiteErrorController.java | 16 +-
.../com/java2nb/common/utils/JSONUtils.java | 144 +++++++++---------
.../src/main/resources/application-dev.yml | 82 +---------
.../src/main/resources/application-prod.yml | 78 +---------
novel-common/pom.xml | 22 +--
.../main/resources/application-common-dev.yml | 45 +-----
.../src/main/resources/application-common.yml | 2 +
novel-crawl/pom.xml | 7 +-
.../novel/core/listener/StarterListener.java | 12 +-
.../src/main/resources/application.yml | 4 +-
novel-front/pom.xml | 7 +-
.../novel/core/listener/StarterListener.java | 32 ++--
.../src/main/resources/application.yml | 2 +
pom.xml | 7 +-
21 files changed, 244 insertions(+), 549 deletions(-)
create mode 100644 config/shardingsphere-jdbc.yml
delete mode 100644 novel-admin/src/main/java/com/java2nb/common/config/DruidDBConfig.java
delete mode 100644 novel-admin/src/main/java/com/java2nb/common/config/Swagger2Config.java
diff --git a/config/shardingsphere-jdbc.yml b/config/shardingsphere-jdbc.yml
new file mode 100644
index 0000000..5f12200
--- /dev/null
+++ b/config/shardingsphere-jdbc.yml
@@ -0,0 +1,53 @@
+mode:
+ # 单机模式
+ type: Standalone
+ # 元数据持久化
+ repository:
+ # 数据库持久化
+ type: JDBC
+
+# 数据源配置
+dataSources:
+ ds_1:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ jdbcUrl: jdbc:mysql://localhost:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+ username: root
+ password: test123456
+ ds_2:
+ dataSourceClassName: com.zaxxer.hikari.HikariDataSource
+ driverClassName: com.mysql.cj.jdbc.Driver
+ url: jdbc:mysql://localhost:3306/information_schema?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
+ username: root
+ password: test123456
+# 规则配置
+rules:
+ - !SINGLE
+ tables:
+ - "*.*"
+ - !SHARDING
+ tables: # 数据分片规则配置
+ book_content:
+ # 分库策略,缺省表示使用默认分库策略
+ actualDataNodes: ds_${1}.book_content${0..9}
+ # 分表策略
+ tableStrategy:
+ standard:
+ # 分片列名称
+ shardingColumn: chapter_id
+ # 分片算法名称
+ shardingAlgorithmName: bookContentSharding
+
+ shardingAlgorithms:
+ bookContentSharding:
+ # 行表达式分片算法,使用 Groovy 的表达式,提供对 SQL 语句中的 = 和 IN 的分片操作支持
+ type: INLINE
+ props:
+ # 分片算法的行表达式
+ algorithm-expression: book_content${chapter_id % 10}
+
+
+
+props:
+ # 是否在日志中打印 SQL
+ sql-show: true
diff --git a/doc/sql/novel_plus.sql b/doc/sql/novel_plus.sql
index 55bd4ad..57748f9 100644
--- a/doc/sql/novel_plus.sql
+++ b/doc/sql/novel_plus.sql
@@ -3145,4 +3145,12 @@ where id = 16;
update crawl_source
-set crawl_rule = replace(crawl_rule, 'xbiqugu.net', 'xbiqugu.la');
\ No newline at end of file
+set crawl_rule = replace(crawl_rule, 'xbiqugu.net', 'xbiqugu.la');
+
+delete
+from sys_menu
+where menu_id = 104;
+
+delete
+from sys_menu
+where menu_id = 57;
\ No newline at end of file
diff --git a/novel-admin/pom.xml b/novel-admin/pom.xml
index c590f48..dbe7fd6 100644
--- a/novel-admin/pom.xml
+++ b/novel-admin/pom.xml
@@ -14,18 +14,14 @@
org.springframework.boot
spring-boot-starter-parent
- 2.1.18.RELEASE
+ 2.7.18
- UTF-8
- UTF-8
- 1.8
+ 17
1.7
- 5.22.0
- 3.0.0
- 2.15.1
+ 5.5.1
@@ -60,35 +56,24 @@
net.sourceforge.nekohtml
nekohtml
+
+
+ org.hibernate.validator
+ hibernate-validator
+
mysql
mysql-connector-java
8.0.29
-
- org.mybatis
- mybatis
- 3.5.6
-
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.1.1
-
-
- com.alibaba
- druid
- 1.2.9
-
-
- org.apache.commons
- commons-lang3
- 3.6
-
commons-configuration
commons-configuration
@@ -138,6 +123,12 @@
org.apache.velocity
velocity
1.7
+
+
+ commons-lang
+ commons-lang
+
+
@@ -166,6 +157,12 @@
io.springfox
springfox-swagger2
2.6.1
+
+
+ guava
+ com.google.guava
+
+
io.springfox
@@ -195,24 +192,29 @@
org.apache.commons
commons-text
1.4
+
+
+ commons-lang3
+ org.apache.commons
+
+
+
- io.shardingsphere
- sharding-jdbc-spring-boot-starter
- ${sharding.jdbc.version}
+ org.apache.shardingsphere
+ shardingsphere-jdbc
+ ${shardingsphere-jdbc.version}
-
- io.shardingsphere
- sharding-jdbc-spring-namespace
- ${sharding.jdbc.version}
+ org.yaml
+ snakeyaml
+ 2.2
-
- com.fasterxml.jackson.core
- jackson-databind
- ${jackson.version}
+ com.h2database
+ h2
+ runtime
diff --git a/novel-admin/src/main/java/com/java2nb/common/aspect/WebLogAspect.java b/novel-admin/src/main/java/com/java2nb/common/aspect/WebLogAspect.java
index 889fdb6..0d6dce5 100644
--- a/novel-admin/src/main/java/com/java2nb/common/aspect/WebLogAspect.java
+++ b/novel-admin/src/main/java/com/java2nb/common/aspect/WebLogAspect.java
@@ -1,19 +1,16 @@
package com.java2nb.common.aspect;
-import com.java2nb.common.utils.HttpContextUtils;
+import com.java2nb.common.utils.IPUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
-import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-import sun.net.util.IPAddressUtil;
import javax.servlet.http.HttpServletRequest;
-import java.lang.reflect.Method;
import java.util.Arrays;
@Aspect
@@ -37,11 +34,10 @@ public class WebLogAspect {
logger.info("请求地址 : " + request.getRequestURL().toString());
logger.info("HTTP METHOD : " + request.getMethod());
// 获取真实的ip地址
- //logger.info("IP : " + IPAddressUtil.getClientIpAddress(request));
+ logger.info("IP : " + IPUtils.getIpAddr(request));
logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
- + joinPoint.getSignature().getName());
+ + joinPoint.getSignature().getName());
logger.info("参数 : " + Arrays.toString(joinPoint.getArgs()));
-// loggger.info("参数 : " + joinPoint.getArgs());
}
diff --git a/novel-admin/src/main/java/com/java2nb/common/config/DruidDBConfig.java b/novel-admin/src/main/java/com/java2nb/common/config/DruidDBConfig.java
deleted file mode 100644
index 92a2383..0000000
--- a/novel-admin/src/main/java/com/java2nb/common/config/DruidDBConfig.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package com.java2nb.common.config;
-import com.alibaba.druid.pool.DruidDataSource;
-import com.alibaba.druid.support.http.StatViewServlet;
-import com.alibaba.druid.support.http.WebStatFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-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 org.springframework.context.annotation.Primary;
-
-import javax.sql.DataSource;
-import java.sql.SQLException;
-
-/**
- * Created by PrimaryKey on 17/2/4.
- */
-@SuppressWarnings("AlibabaRemoveCommentedCode")
-@Configuration
-public class DruidDBConfig {
- private Logger logger = LoggerFactory.getLogger(DruidDBConfig.class);
- @Value("${spring.datasource.url}")
- private String dbUrl;
-
- @Value("${spring.datasource.username}")
- private String username;
-
- @Value("${spring.datasource.password}")
- private String password;
-
- @Value("${spring.datasource.driverClassName}")
- private String driverClassName;
-
- @Value("${spring.datasource.initialSize}")
- private int initialSize;
-
- @Value("${spring.datasource.minIdle}")
- private int minIdle;
-
- @Value("${spring.datasource.maxActive}")
- private int maxActive;
-
- @Value("${spring.datasource.maxWait}")
- private int maxWait;
-
- @Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
- private int timeBetweenEvictionRunsMillis;
-
- @Value("${spring.datasource.minEvictableIdleTimeMillis}")
- private int minEvictableIdleTimeMillis;
-
- @Value("${spring.datasource.validationQuery}")
- private String validationQuery;
-
- @Value("${spring.datasource.testWhileIdle}")
- private boolean testWhileIdle;
-
- @Value("${spring.datasource.testOnBorrow}")
- private boolean testOnBorrow;
-
- @Value("${spring.datasource.testOnReturn}")
- private boolean testOnReturn;
-
- @Value("${spring.datasource.poolPreparedStatements}")
- private boolean poolPreparedStatements;
-
- @Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
- private int maxPoolPreparedStatementPerConnectionSize;
-
- @Value("${spring.datasource.filters}")
- private String filters;
-
- @Value("{spring.datasource.connectionProperties}")
- private String connectionProperties;
-
- @Bean(initMethod = "init", destroyMethod = "close") //声明其为Bean实例
- @Primary //在同样的DataSource中,首先使用被标注的DataSource
- public DataSource dataSource() {
- DruidDataSource datasource = new DruidDataSource();
-
- datasource.setUrl(this.dbUrl);
- datasource.setUsername(username);
- datasource.setPassword(password);
- datasource.setDriverClassName(driverClassName);
-
- //configuration
- datasource.setInitialSize(initialSize);
- datasource.setMinIdle(minIdle);
- datasource.setMaxActive(maxActive);
- datasource.setMaxWait(maxWait);
- datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
- datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
- datasource.setValidationQuery(validationQuery);
- datasource.setTestWhileIdle(testWhileIdle);
- datasource.setTestOnBorrow(testOnBorrow);
- datasource.setTestOnReturn(testOnReturn);
- datasource.setPoolPreparedStatements(poolPreparedStatements);
- datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
- try {
- datasource.setFilters(filters);
- } catch (SQLException e) {
- logger.error("druid configuration initialization filter", e);
- }
- datasource.setConnectionProperties(connectionProperties);
-
- return datasource;
- }
-
- @Bean
- public ServletRegistrationBean druidServlet() {
- ServletRegistrationBean reg = new ServletRegistrationBean();
- reg.setServlet(new StatViewServlet());
- reg.addUrlMappings("/druid/*");
- reg.addInitParameter("allow", ""); //白名单
- return reg;
- }
-
- @Bean public FilterRegistrationBean filterRegistrationBean() {
- FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
- filterRegistrationBean.setFilter(new WebStatFilter());
- filterRegistrationBean.addUrlPatterns("/*");
- filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
- filterRegistrationBean.addInitParameter("profileEnable", "true");
- filterRegistrationBean.addInitParameter("principalCookieName","USER_COOKIE");
- filterRegistrationBean.addInitParameter("principalSessionName","USER_SESSION");
- filterRegistrationBean.addInitParameter("DruidWebStatFilter","/*");
- return filterRegistrationBean;
- }
-}
-
diff --git a/novel-admin/src/main/java/com/java2nb/common/config/Swagger2Config.java b/novel-admin/src/main/java/com/java2nb/common/config/Swagger2Config.java
deleted file mode 100644
index 90b912c..0000000
--- a/novel-admin/src/main/java/com/java2nb/common/config/Swagger2Config.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.java2nb.common.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import springfox.documentation.builders.ApiInfoBuilder;
-import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.builders.RequestHandlerSelectors;
-import springfox.documentation.service.ApiInfo;
-import springfox.documentation.service.Contact;
-import springfox.documentation.spi.DocumentationType;
-import springfox.documentation.spring.web.plugins.Docket;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
-/**
- * ${DESCRIPTION}
- *
- * @author xiongxy
- * @create 2019-11-02 23:53
- */
-@EnableSwagger2
-@Configuration
-public class Swagger2Config {
-
- @Bean
- public Docket createRestApi() {
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- .select()
- //为当前包路径
- .apis(RequestHandlerSelectors.any())
- .paths(PathSelectors.any())
- .build();
- }
-
- //构建 api文档的详细信息函数
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- //页面标题
- .title("功能测试")
- //创建人
- .contact(new Contact("xiongxy", "1179705413@qq.com", "1179705413@qq.com"))
- //版本号
- .version("1.0")
- //描述
- .description("API 描述")
- .build();
- }
-}
\ No newline at end of file
diff --git a/novel-admin/src/main/java/com/java2nb/common/dao/GeneratorMapper.java b/novel-admin/src/main/java/com/java2nb/common/dao/GeneratorMapper.java
index 38996bb..914affc 100644
--- a/novel-admin/src/main/java/com/java2nb/common/dao/GeneratorMapper.java
+++ b/novel-admin/src/main/java/com/java2nb/common/dao/GeneratorMapper.java
@@ -9,25 +9,25 @@ import java.util.Map;
public interface GeneratorMapper {
@Select(
- "select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
+ "select table_name tableName, engine, table_comment tableComment, create_time createTime from tables"
+ " where table_schema = 'novel_plus' and table_name like concat('%',#{tableName},'%')")
List
diff --git a/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java b/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java
index 41d5a5f..96a6b48 100644
--- a/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java
+++ b/novel-front/src/main/java/com/java2nb/novel/core/listener/StarterListener.java
@@ -5,36 +5,34 @@ import com.java2nb.novel.entity.WebsiteInfo;
import com.java2nb.novel.mapper.WebsiteInfoMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.web.servlet.ServletContextInitializer;
+import org.springframework.stereotype.Component;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.annotation.WebListener;
+import javax.servlet.ServletContext;
/**
* 启动监听器
*
* @author xiongxiaoyang
*/
-@WebListener
+@Component
@Slf4j
@RequiredArgsConstructor
-public class StarterListener implements ServletContextListener {
+public class StarterListener implements ServletContextInitializer {
private final WebsiteProperties websiteProperties;
-
private final WebsiteInfoMapper websiteInfoMapper;
@Override
- public void contextInitialized(ServletContextEvent sce) {
- sce.getServletContext()
- .setAttribute("website", websiteInfoMapper.selectByPrimaryKey(1L).orElse(new WebsiteInfo() {{
- setName(websiteProperties.getName());
- setDomain(websiteProperties.getDomain());
- setKeyword(websiteProperties.getKeyword());
- setDescription(websiteProperties.getDescription());
- setQq(websiteProperties.getQq());
- setLogo("/images/logo.png");
- setLogoDark("/images/logo_white.png");
- }}));
+ public void onStartup(ServletContext servletContext) {
+ servletContext.setAttribute("website", websiteInfoMapper.selectByPrimaryKey(1L).orElse(new WebsiteInfo() {{
+ setName(websiteProperties.getName());
+ setDomain(websiteProperties.getDomain());
+ setKeyword(websiteProperties.getKeyword());
+ setDescription(websiteProperties.getDescription());
+ setQq(websiteProperties.getQq());
+ setLogo("/images/logo.png");
+ setLogoDark("/images/logo_white.png");
+ }}));
}
}
diff --git a/novel-front/src/main/resources/application.yml b/novel-front/src/main/resources/application.yml
index 5261537..26cb4c3 100644
--- a/novel-front/src/main/resources/application.yml
+++ b/novel-front/src/main/resources/application.yml
@@ -5,6 +5,8 @@ spring:
profiles:
active: dev
include: website,alipay,oss
+ config:
+ use-legacy-processing: true
jwt:
secret: novel!#20191230
diff --git a/pom.xml b/pom.xml
index 80455b9..d91feb3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,14 +20,14 @@
org.springframework.boot
spring-boot-starter-parent
- 2.1.18.RELEASE
+ 2.7.18
UTF-8
UTF-8
- 1.8
+ 17
true
8.0.29
2.1.4
@@ -40,12 +40,11 @@
6.3.1
1.4.1.RELEASE
3.12.5
- 3.0.0
+ 5.5.1
3.16.3
1.5
4.35.139.ALL
1.0.0
- 2.15.1