创建名为“defaultTbMailConfigTemplateService”的 bean 时出错 Thingsboard release-3.6

问题描述 投票:0回答:1

我已经从源代码构建了 thingsboard release-3.6 版本。 我在应用程序/目标中运行 boot-jar 文件时遇到问题,收到以下错误。

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultTbMailConfigTemplateService': Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [templates/mail_config_templates.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/thingspad/Documents/thingsboard/application/target/thingsboard-3.6.1-SNAPSHOT-boot.jar!/BOOT-INF/classes!/templates/mail_config_templates.json

thingsboard 的 Maven 构建没有问题,启动 boot-jar 文件时出现问题。 Error while running boot jar

有人可以帮我解决我面临的问题吗?

提前致谢

java maven javabeans thingsboard
1个回答
0
投票

我已经看到了下面的代码。解析资源的文件路径时出现问题

templates/mail_config_templates.json

@PostConstruct
private void postConstruct() throws IOException {
    mailConfigTemplates = JacksonUtil.toJsonNode(new ClassPathResource("/templates/mail_config_templates.json").getFile());
}

该文件似乎位于 JAR 文件内,并且应用程序无法解析其绝对文件路径,因为它无法在文件系统中直接访问。

在这里您可以检查潜在的解决方案:

@PostConstruct
private void postConstruct() throws IOException {
    try (InputStream inputStream = getClass().getResourceAsStream("/templates/mail_config_templates.json")) {
        if (inputStream == null) {
            throw new FileNotFoundException("File not found: mail_config_templates.json");
        }
        mailConfigTemplates = JacksonUtil.toJsonNode(new String(inputStream.readAllBytes(), StandardCharsets.UTF_8));
    } catch (IOException e) {
        log.error("Error loading mail configuration templates", e);
        throw e;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.