From e4aa453e391dae5b686a5e9328ae421872f7fd90 Mon Sep 17 00:00:00 2001 From: tongtongstudio Date: Tue, 20 Jan 2026 09:28:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=87=B3springboot4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DockerFileJava25 | 10 ++++++++ pom.xml | 14 +++++++---- .../videotablet/config/SecurityConfig.java | 3 ++- .../sn/DeviceApkInfoController.java | 7 ------ .../filter/JwtAuthenticationFilter.java | 7 ++++-- .../resources/application-debug.properties | 6 +++-- .../resources/application-prod.properties | 6 +++-- .../resources/application-test.properties | 24 ++++++++++--------- 8 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 DockerFileJava25 diff --git a/DockerFileJava25 b/DockerFileJava25 new file mode 100644 index 0000000..4045e5b --- /dev/null +++ b/DockerFileJava25 @@ -0,0 +1,10 @@ +FROM eclipse-temurin:25-jdk-jammy +MAINTAINER TongTongStudio +RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak + +RUN mkdir -p /data/uploads/ + +VOLUME /tmp +ADD target/*.jar app.jar +EXPOSE 8088 +ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5c7324b..7fae052 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.springframework.boot spring-boot-starter-parent - 3.5.4 + 4.0.1 com.onekeycall @@ -34,7 +34,7 @@ - 21 + 25 2025.0.0 @@ -89,8 +89,12 @@ org.springframework.boot - spring-boot-starter-oauth2-client + spring-boot-starter-security-oauth2-client + + + + org.springframework.boot spring-boot-starter-oauth2-resource-server @@ -108,7 +112,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 3.0.3 + 4.0.1 @@ -200,7 +204,7 @@ io.jsonwebtoken jjwt-jackson - 0.12.3 + 0.12.6 runtime diff --git a/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java b/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java index ba85894..f21e897 100644 --- a/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java +++ b/src/main/java/com/onekeycall/videotablet/config/SecurityConfig.java @@ -9,6 +9,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -18,7 +19,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic @Configuration @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true) +@EnableMethodSecurity public class SecurityConfig { private final JwtAuthenticationFilter jwtAuthenticationFilter; // 自定义的JWT认证过滤器 diff --git a/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java b/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java index 55b2b44..aa132ff 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java @@ -1,6 +1,5 @@ package com.onekeycall.videotablet.controller.sn; -import com.fasterxml.jackson.databind.ObjectMapper; import com.onekeycall.videotablet.bean.ApkUploadRequest; import com.onekeycall.videotablet.entity.ApkInfo; import com.onekeycall.videotablet.result.Result; @@ -17,12 +16,6 @@ import java.util.List; public class DeviceApkInfoController { static Logger logger = LoggerFactory.getLogger(DeviceApkInfoController.class); - private final ObjectMapper objectMapper; // Spring默认已注入 - - public DeviceApkInfoController(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } - @Autowired private DeviceApkInfoService deviceApkInfoService; diff --git a/src/main/java/com/onekeycall/videotablet/filter/JwtAuthenticationFilter.java b/src/main/java/com/onekeycall/videotablet/filter/JwtAuthenticationFilter.java index 027c5e4..487dc89 100644 --- a/src/main/java/com/onekeycall/videotablet/filter/JwtAuthenticationFilter.java +++ b/src/main/java/com/onekeycall/videotablet/filter/JwtAuthenticationFilter.java @@ -33,6 +33,9 @@ import java.nio.charset.StandardCharsets; public class JwtAuthenticationFilter extends OncePerRequestFilter { Logger logger = LoggerFactory.getLogger(JwtAuthenticationFilter.class); + // 推荐的缓存上限:20480字节 = 20KB,Spring5.x的默认值 + private static final int DEFAULT_CACHE_LIMIT = 20480; + private final UserService userService; private final JwtUtil jwtUtil; @@ -44,7 +47,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { // 使用ContentCachingRequestWrapper包装请求以支持多次读取 - ContentCachingRequestWrapper wrappedRequest = new ContentCachingRequestWrapper(request); + ContentCachingRequestWrapper wrappedRequest = new ContentCachingRequestWrapper(request, DEFAULT_CACHE_LIMIT); String uripath = wrappedRequest.getRequestURI(); // 新增请求路径日志 @@ -77,7 +80,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { setUnauthorizedResponse(response, Result.unAuthorized().message("Invalid credentials")); return; // 重要!验证失败时终止过滤器链 } - }else { + } else { logger.error("Authorization header format error | Header: " + authorizationHeader); setUnauthorizedResponse(response, Result.unAuthorized().message("Authorization header format error")); return; // 重要!验证失败时终止过滤器链 diff --git a/src/main/resources/application-debug.properties b/src/main/resources/application-debug.properties index 2600656..d3077f1 100644 --- a/src/main/resources/application-debug.properties +++ b/src/main/resources/application-debug.properties @@ -1,6 +1,8 @@ spring.application.name=VideoTablet server.port=8088 +spring.threads.virtual.enabled=true + ## mysql 数据连接信息 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true @@ -23,11 +25,11 @@ spring.data.redis.lettuce.pool.max-wait=1ms spring.data.redis.lettuce.shutdown-timeout=100ms #MongoDB -spring.data.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000 +spring.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000 # Hibernate配置 #spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 1637d26..577a72e 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -1,6 +1,8 @@ spring.application.name=VideoTablet server.port=8088 +spring.threads.virtual.enabled=true + ## mysql 数据连接信息 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://139.199.77.221:13306/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true @@ -23,11 +25,11 @@ spring.data.redis.lettuce.pool.max-wait=1ms spring.data.redis.lettuce.shutdown-timeout=100ms #MongoDB -spring.data.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000 +spring.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000 # Hibernate配置 #spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index cdf44f8..13426ab 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -1,17 +1,19 @@ spring.application.name=VideoTablet server.port=8088 -## mysql 数据连接信息 -#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -#spring.datasource.url=jdbc:mysql://139.199.77.221:13306/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true -#spring.datasource.username=tt -#spring.datasource.password=fanhuitong +spring.threads.virtual.enabled=true -# PostgreSQL 数据源配置 -spring.datasource.url=jdbc:postgresql://139.199.77.221:5433/video_tablet_db -spring.datasource.username=postgres +# mysql 数据连接信息 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://139.199.77.221:13306/video_tablet_db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true +spring.datasource.username=tt spring.datasource.password=fanhuitong -spring.datasource.driver-class-name=org.postgresql.Driver + +## PostgreSQL 数据源配置 +#spring.datasource.url=jdbc:postgresql://139.199.77.221:5433/video_tablet_db +#spring.datasource.username=postgres +#spring.datasource.password=fanhuitong +#spring.datasource.driver-class-name=org.postgresql.Driver # redis基础配置 # 0也是默认值,表示你要操控的 Redis 上的哪个数据库 @@ -29,11 +31,11 @@ spring.data.redis.lettuce.pool.max-wait=1ms spring.data.redis.lettuce.shutdown-timeout=100ms #MongoDB -spring.data.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000 +spring.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000 # Hibernate配置 #spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true