From 536a8f07adb6c355e319e16a79c740d606e814ad Mon Sep 17 00:00:00 2001 From: SHIMHUN Date: Fri, 24 Apr 2026 02:15:56 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20FCM=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B3=84=EC=A0=95=20=ED=8C=8C=EC=9D=BC=EC=9D=84=20classpath?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=A1=9C=EB=93=9C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/config/firebase/FcmConfig.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/com/eatall/backend/config/firebase/FcmConfig.java b/backend/src/main/java/com/eatall/backend/config/firebase/FcmConfig.java index 09c2910..fa17816 100644 --- a/backend/src/main/java/com/eatall/backend/config/firebase/FcmConfig.java +++ b/backend/src/main/java/com/eatall/backend/config/firebase/FcmConfig.java @@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; import java.io.InputStream; import java.nio.file.Files; @@ -26,13 +27,11 @@ public void initialize() { return; } - Path path = Path.of(keyPath); - if (!Files.exists(path)) { - log.warn("FCM service account key file not found at: {}", keyPath); - return; - } + try (InputStream serviceAccount = getServiceAccountInputStream()) { + if (serviceAccount == null) { + return; + } - try (InputStream serviceAccount = Files.newInputStream(path)) { FirebaseOptions options = FirebaseOptions.builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount)) .build(); @@ -46,4 +45,23 @@ public void initialize() { log.error("FCM initialization failed", e); } } + + private InputStream getServiceAccountInputStream() throws Exception { + if (keyPath.startsWith("classpath:")) { + String resourcePath = keyPath.substring("classpath:".length()); + ClassPathResource resource = new ClassPathResource(resourcePath); + if (!resource.exists()) { + log.warn("FCM service account resource not found in classpath: {}", keyPath); + return null; + } + return resource.getInputStream(); + } + + Path path = Path.of(keyPath); + if (!Files.exists(path)) { + log.warn("FCM service account key file not found at: {}", keyPath); + return null; + } + return Files.newInputStream(path); + } } \ No newline at end of file