迁移至springboot4

This commit is contained in:
2026-01-20 09:28:00 +08:00
parent 683c45c027
commit e4aa453e39
8 changed files with 47 additions and 30 deletions

View File

@@ -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认证过滤器

View File

@@ -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;

View File

@@ -33,6 +33,9 @@ import java.nio.charset.StandardCharsets;
public class JwtAuthenticationFilter extends OncePerRequestFilter {
Logger logger = LoggerFactory.getLogger(JwtAuthenticationFilter.class);
// 推荐的缓存上限20480字节 = 20KBSpring5.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; // 重要!验证失败时终止过滤器链

View File

@@ -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

View File

@@ -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

View File

@@ -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