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