feat(部署): 优化部署目录

This commit is contained in:
2026-08-27 14:42:14 +08:00
parent 19bc987f36
commit 01fad1b65a
8 changed files with 139 additions and 23 deletions
@@ -15,8 +15,9 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(@NonNull ResourceHandlerRegistry registry) {
// 配置静态资源处理
// 部署时可将 static/ 挂载到工作目录,优先于 jar 内 classpath
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
.addResourceLocations("file:./static/", "classpath:/static/");
// 配置上传文件访问 - 使用绝对路径
registry.addResourceHandler("/uploads/**")
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.open.api.extension.features.service.im
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.StreamUtils;
@@ -20,20 +21,20 @@ import java.nio.file.Path;
import java.nio.file.Paths;
/**
* 从 classpath:static/extension-features/ 读取扩展功能清单与脚本。
* 读取扩展功能清单与脚本;优先 ./static/extension-features/(部署挂载),否则 classpath。
*/
@Service
@RequiredArgsConstructor
public class ExtensionFeatureServiceImpl implements ExtensionFeatureService {
private static final String MANIFEST_PATH = "static/extension-features/manifest.json";
private static final String FEATURE_DIR = "static/extension-features/";
private static final String MANIFEST_REL = "extension-features/manifest.json";
private static final String FEATURE_DIR_REL = "extension-features/";
private final ObjectMapper objectMapper;
@Override
public ExtensionFeatureManifestVO getManifest() {
Resource resource = new ClassPathResource(MANIFEST_PATH);
Resource resource = resolveFeatureResource(MANIFEST_REL);
if (!resource.exists()) {
throw new BusinessException("扩展功能清单不存在,请先部署 dist-features 到 static/extension-features/");
}
@@ -65,7 +66,7 @@ public class ExtensionFeatureServiceImpl implements ExtensionFeatureService {
throw new BusinessException("非法脚本路径");
}
Resource resource = new ClassPathResource(FEATURE_DIR + normalized);
Resource resource = resolveFeatureResource(FEATURE_DIR_REL + normalized);
if (!resource.exists()) {
throw new BusinessException("功能脚本文件不存在: " + entry);
}
@@ -81,4 +82,13 @@ public class ExtensionFeatureServiceImpl implements ExtensionFeatureService {
throw new BusinessException("读取功能脚本失败: " + e.getMessage());
}
}
/** 挂载目录 static/extension-features 优先于 jar 内资源 */
private Resource resolveFeatureResource(String relativePath) {
FileSystemResource mounted = new FileSystemResource(Paths.get("static", relativePath));
if (mounted.exists()) {
return mounted;
}
return new ClassPathResource("static/" + relativePath);
}
}
@@ -7,6 +7,7 @@ spring:
config:
import:
- optional:classpath:config/channel-pdd.yml
- optional:file:./config/channel-pdd.yml
jackson:
time-zone: Asia/Shanghai
mvc: