修改相关资源路径
This commit is contained in:
@@ -14,7 +14,7 @@ FROM eclipse-temurin:17-jre-alpine
|
||||
WORKDIR /app
|
||||
|
||||
# 复制部署结构:bin/ libs/ etc/
|
||||
COPY --from=builder /app/src/main/scripts/start.sh bin/start.sh
|
||||
COPY --from=builder /app/scripts/start.sh bin/start.sh
|
||||
COPY --from=builder /app/target/libs/ libs/
|
||||
COPY --from=builder /app/src/main/resources/application.yml etc/application.yml
|
||||
COPY --from=builder /app/src/main/resources/logback.xml etc/logback.xml
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<!-- bin/start.sh(0755 可执行) -->
|
||||
<files>
|
||||
<file>
|
||||
<source>src/main/scripts/start.sh</source>
|
||||
<source>scripts/start.sh</source>
|
||||
<outputDirectory>bin</outputDirectory>
|
||||
<fileMode>0755</fileMode>
|
||||
</file>
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
<!-- logs/ 空目录占位 -->
|
||||
<fileSet>
|
||||
<directory>src/main/assembly/empty-logs</directory>
|
||||
<directory>assembly/empty-logs</directory>
|
||||
<outputDirectory>logs</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
@@ -11,7 +11,7 @@ services:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
- ./src/main/resources/sql/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U label -d label_db"]
|
||||
interval: 10s
|
||||
|
||||
12
pom.xml
12
pom.xml
@@ -132,6 +132,14 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>sql/**</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<!-- 薄 jar:仅打包编译后的 class,输出到 target/libs/ -->
|
||||
<plugin>
|
||||
@@ -178,7 +186,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/distribution.xml</descriptor>
|
||||
<descriptor>assembly/distribution.xml</descriptor>
|
||||
</descriptors>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
@@ -188,4 +196,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.label.common.context;
|
||||
|
||||
import com.label.common.auth.TokenPrincipal;
|
||||
|
||||
public final class UserContext {
|
||||
private static final ThreadLocal<TokenPrincipal> PRINCIPAL = new ThreadLocal<>();
|
||||
|
||||
public static void set(TokenPrincipal principal) {
|
||||
PRINCIPAL.set(principal);
|
||||
}
|
||||
|
||||
public static TokenPrincipal get() {
|
||||
return PRINCIPAL.get();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
PRINCIPAL.remove();
|
||||
}
|
||||
|
||||
private UserContext() {
|
||||
throw new UnsupportedOperationException("Utility class");
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.label.annotation.RequireRole;
|
||||
import com.label.common.auth.TokenPrincipal;
|
||||
import com.label.common.context.CompanyContext;
|
||||
import com.label.common.context.UserContext;
|
||||
import com.label.common.result.Result;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisUtil;
|
||||
@@ -79,7 +78,6 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
|
||||
Object handler, Exception ex) {
|
||||
UserContext.clear();
|
||||
CompanyContext.clear();
|
||||
}
|
||||
|
||||
@@ -125,7 +123,6 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
|
||||
private void bindPrincipal(HttpServletRequest request, TokenPrincipal principal) {
|
||||
CompanyContext.set(principal.getCompanyId());
|
||||
UserContext.set(principal);
|
||||
request.setAttribute("__token_principal__", principal);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ spring:
|
||||
application:
|
||||
name: label-backend
|
||||
datasource:
|
||||
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/labeldb}
|
||||
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://39.107.112.174:5432/labeldb}
|
||||
username: ${SPRING_DATASOURCE_USERNAME:postgres}
|
||||
password: ${SPRING_DATASOURCE_PASSWORD:}
|
||||
password: ${SPRING_DATASOURCE_PASSWORD:postgres!Pw}
|
||||
driver-class-name: org.postgresql.Driver
|
||||
hikari:
|
||||
maximum-pool-size: 20
|
||||
@@ -16,9 +16,9 @@ spring:
|
||||
|
||||
data:
|
||||
redis:
|
||||
host: ${SPRING_DATA_REDIS_HOST:localhost}
|
||||
host: ${SPRING_DATA_REDIS_HOST:39.107.112.174}
|
||||
port: ${SPRING_DATA_REDIS_PORT:6379}
|
||||
password: ${SPRING_DATA_REDIS_PASSWORD:}
|
||||
password: ${SPRING_DATA_REDIS_PASSWORD:jsti@2024}
|
||||
timeout: 5000ms
|
||||
lettuce:
|
||||
pool:
|
||||
@@ -54,9 +54,9 @@ mybatis-plus:
|
||||
id-type: auto
|
||||
|
||||
rustfs:
|
||||
endpoint: ${RUSTFS_ENDPOINT:http://localhost:9000}
|
||||
endpoint: ${RUSTFS_ENDPOINT:http://39.107.112.174:9000}
|
||||
access-key: ${RUSTFS_ACCESS_KEY:admin}
|
||||
secret-key: ${RUSTFS_SECRET_KEY:local-secret-key}
|
||||
secret-key: ${RUSTFS_SECRET_KEY:your_strong_password}
|
||||
region: us-east-1
|
||||
|
||||
ai-service:
|
||||
@@ -64,7 +64,7 @@ ai-service:
|
||||
timeout: 30000
|
||||
|
||||
auth:
|
||||
enabled: true
|
||||
enabled: false
|
||||
mock-company-id: 1
|
||||
mock-user-id: 1
|
||||
mock-role: ADMIN
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.label.annotation.RequireAuth;
|
||||
import com.label.annotation.RequireRole;
|
||||
import com.label.common.auth.TokenPrincipal;
|
||||
import com.label.common.context.CompanyContext;
|
||||
import com.label.common.context.UserContext;
|
||||
import com.label.interceptor.AuthInterceptor;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisUtil;
|
||||
@@ -22,6 +21,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -36,7 +36,6 @@ class AuthInterceptorTest {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
CompanyContext.clear();
|
||||
UserContext.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +61,6 @@ class AuthInterceptorTest {
|
||||
assertThat(principal.getUserId()).isEqualTo(10L);
|
||||
assertThat(principal.getRole()).isEqualTo("ADMIN");
|
||||
assertThat(CompanyContext.get()).isEqualTo(20L);
|
||||
assertThat(UserContext.get()).isSameAs(principal);
|
||||
verify(redisService).expire(RedisUtil.tokenKey("valid-token"), 7200L);
|
||||
verify(redisService).expire(RedisUtil.userSessionsKey(10L), 7200L);
|
||||
}
|
||||
@@ -118,16 +116,21 @@ class AuthInterceptorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("请求完成后清理用户和公司 ThreadLocal")
|
||||
void afterCompletionClearsContexts() throws Exception {
|
||||
@DisplayName("UserContext 已被移除,避免重复维护用户 ThreadLocal")
|
||||
void userContextClassShouldBeRemoved() {
|
||||
assertThatThrownBy(() -> Class.forName("com.label.common.context.UserContext"))
|
||||
.isInstanceOf(ClassNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("请求完成后清理公司 ThreadLocal")
|
||||
void afterCompletionClearsCompanyContext() throws Exception {
|
||||
CompanyContext.set(20L);
|
||||
UserContext.set(new TokenPrincipal(10L, "ADMIN", 20L, "admin", "token"));
|
||||
|
||||
interceptor.afterCompletion(new MockHttpServletRequest(), new MockHttpServletResponse(),
|
||||
handler("adminOnly"), null);
|
||||
|
||||
assertThat(CompanyContext.get()).isEqualTo(-1L);
|
||||
assertThat(UserContext.get()).isNull();
|
||||
}
|
||||
|
||||
private static HandlerMethod handler(String methodName) throws NoSuchMethodException {
|
||||
|
||||
Reference in New Issue
Block a user