diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java index 06dec9af4ee..595c9a5c8df 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java @@ -64,6 +64,8 @@ @Slf4j public class AppServiceImpl implements AppService, CommandLineRunner { + private static final String JAVA_PATH_SEPARATOR = "/"; + @Autowired private MonitorDao monitorDao; @@ -193,22 +195,25 @@ public String getMonitorDefineFileContent(String app) { String defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml"; File defineAppFile = new File(defineAppPath); if (!defineAppFile.exists() || !defineAppFile.isFile()) { - classpath = Objects.requireNonNull(this.getClass().getResource(File.separator)).getPath(); - defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml"; - defineAppFile = new File(defineAppPath); - if (!defineAppFile.exists() || !defineAppFile.isFile()) { - try { - // load define app yml in jar - log.info("load define app yml in internal jar"); - ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - Resource resource = resolver.getResource("classpath:define/" + app + ".yml"); - InputStream inputStream = resource.getInputStream(); - String content = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8); - inputStream.close(); - return content; - } catch (Exception e) { - log.error(e.getMessage()); - } + URL resourceUrl = this.getClass().getResource(JAVA_PATH_SEPARATOR); + if (resourceUrl != null) { + classpath = resourceUrl.getPath(); + defineAppPath = classpath + "define" + File.separator + "app-" + app + ".yml"; + defineAppFile = new File(defineAppPath); + if (!defineAppFile.exists() || !defineAppFile.isFile()) { + try { + // load define app yml in jar + log.info("load define app yml in internal jar"); + ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + Resource resource = resolver.getResource("classpath:define/" + app + ".yml"); + InputStream inputStream = resource.getInputStream(); + String content = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8); + inputStream.close(); + return content; + } catch (Exception e) { + log.error(e.getMessage()); + } + } } } log.info("load {} define app yml in file: {}", app, defineAppPath); diff --git a/web-app/src/app/routes/setting/define/define.component.ts b/web-app/src/app/routes/setting/define/define.component.ts index d5dc15d1552..2fe02fc82f4 100644 --- a/web-app/src/app/routes/setting/define/define.component.ts +++ b/web-app/src/app/routes/setting/define/define.component.ts @@ -39,7 +39,9 @@ export class DefineComponent implements OnInit { ngOnInit(): void { this.route.queryParamMap.subscribe((paramMap: ParamMap) => { this.currentApp = paramMap.get('app') || undefined; - this.loadAppDefineContent(this.currentApp); + if (this.currentApp != undefined) { + this.loadAppDefineContent(this.currentApp); + } }); this.loadMenus(); this.code = `${this.i18nSvc.fanyi('define.new.code')}\n\n\n\n\n`;