效果
在本地化部署的时候,直接去读取本地部署文件目录的conf下的配置文件,从而实现配置文件不直接进入到打包的jar里。
实现过程
1)系统配置文件工具类

public class SystemPropertyUtil {
// 知识库提示词文件路径
public static final String KnowledgePromptFilePath;
static {
KnowledgePromptFilePath = System.getProperty("user.dir") + "/knowledge_prompt.txt";
}
public static void setSystemUserDir() {
String dir = System.getProperty("user.dir");
String conf = String.format("%s/%s", dir, "conf");
File file = new File(conf);
if(!file.exists()) {
dir = dir.substring(0, dir.lastIndexOf("/"));
conf = String.format("%s/%s", dir, "conf");
file = new File(conf);
if(file.exists()) {
System.setProperty("user.dir", dir);
}
}
System.setProperty("user.dir.conf", System.getProperty("user.dir") + "/conf");
System.out.println("Config path: " + System.getProperty("user.dir.conf"));
}
// 获取自定义关键词配置文件路径
public static String getCustomKeywordsFilePath() {
return getSystemUserDir() + "/custom_keywords.txt";
}
// 获取自定义关键词配置文件路径
public static String getKnowledgePromptFilePath() {
return getSystemUserDir() + "/dtstack-knowledge-prompt-template.txt";
}
public static String getSystemUserDir() {
return System.getProperty("user.dir.conf");
}
}
2、启动器服务

public static void main(String[] args) {
SystemPropertyUtil.setSystemUserDir();
// SpringApplication.run(KnowLedgeServerApplication.class, args);
new SpringApplicationBuilder(KnowLedgeServerApplication.class)
.properties(
"spring.config.location=file:${user.dir.conf}/application.yaml",
"spring.web.resources.static-locations=file:${user.dir.conf}/static/"
)
.run(args);
}
**或者配置文件补充配置:**application.properties
spring.web.resources.static-locations=file:${user.dir.conf}/static/
ps:针对于springboot 的版本为:2.3.12.RELEASE,则需要配置参数为:
new SpringApplicationBuilder(SqlParserXWebApplication.class)
.properties(
"spring.config.location=file:${user.dir.conf}/application.properties",
"spring.resources.static-locations=file:${user.dir.conf}/static/"
).run(args);
评论区请在客户端页面查看