From e3ead5d49193334869103063695de6a17b759a06 Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:20:00 +0200 Subject: [PATCH] Fix deployed exception --- .../com/uniovi/services/QuestionGeneratorService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/uniovi/services/QuestionGeneratorService.java b/src/main/java/com/uniovi/services/QuestionGeneratorService.java index d4e35327..3a800243 100644 --- a/src/main/java/com/uniovi/services/QuestionGeneratorService.java +++ b/src/main/java/com/uniovi/services/QuestionGeneratorService.java @@ -16,6 +16,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -31,7 +33,7 @@ public class QuestionGeneratorService { private final QuestionService questionService; - public static final String JSON_FILE_PATH = "src/main/resources/static/JSON/QuestionTemplates.json"; + public static final String JSON_FILE_PATH = "static/JSON/QuestionTemplates.json"; private Deque types = new ArrayDeque<>(); @@ -52,9 +54,9 @@ public QuestionGeneratorService(QuestionService questionService, Environment env } private void parseQuestionTypes() throws IOException { - File jsonFile = new File(JSON_FILE_PATH); + Resource resource = new ClassPathResource(JSON_FILE_PATH); ObjectMapper objectMapper = new ObjectMapper(); - json = objectMapper.readTree(jsonFile); + json = objectMapper.readTree(resource.getInputStream()); JsonNode categories = json.findValue("categories"); for (JsonNode category : categories) { String categoryName = category.get("name").textValue();