From c213d588c2dfcd26c599a67873f15da860322ff8 Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Wed, 5 Jun 2024 22:17:34 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=20#62=20firebaseconfig=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/config/FirebaseConfig.java | 24 +++++++++---------- .../server/service/fcm/FcmService.java | 3 +-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/telepigeon/server/config/FirebaseConfig.java b/src/main/java/com/telepigeon/server/config/FirebaseConfig.java index 98917c2..82401e8 100644 --- a/src/main/java/com/telepigeon/server/config/FirebaseConfig.java +++ b/src/main/java/com/telepigeon/server/config/FirebaseConfig.java @@ -3,35 +3,35 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; -import com.google.firebase.messaging.FirebaseMessaging; import com.telepigeon.server.exception.NotFoundException; import com.telepigeon.server.exception.code.NotFoundErrorCode; -import org.springframework.context.annotation.Bean; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; +import javax.annotation.PostConstruct; import java.io.FileInputStream; import java.io.IOException; +@Slf4j @Configuration public class FirebaseConfig { - @Bean - public FirebaseApp firebaseApp() { - if (!FirebaseApp.getApps().isEmpty()) - return FirebaseApp.getInstance(); + @PostConstruct + public void firebaseApp() { + if (!FirebaseApp.getApps().isEmpty()) { + log.info("FirebaseApp already initialized"); + FirebaseApp.getInstance(); + } try { FileInputStream aboutFirebaseFile = new FileInputStream("src/main/resources/firebase.json"); FirebaseOptions options = FirebaseOptions .builder() .setCredentials(GoogleCredentials.fromStream(aboutFirebaseFile)) .build(); - return FirebaseApp.initializeApp(options); + log.info("FirebaseApp initialize"); + FirebaseApp.initializeApp(options); } catch (IOException e) { + log.error("FirebaseApp initialize failed : {}", e.getMessage()); throw new NotFoundException(NotFoundErrorCode.FIREBASE_JSON_NOT_FOUND); } } - - @Bean - public FirebaseMessaging firebaseMessaging(FirebaseApp firebaseApp) { - return FirebaseMessaging.getInstance(firebaseApp); - } } \ No newline at end of file diff --git a/src/main/java/com/telepigeon/server/service/fcm/FcmService.java b/src/main/java/com/telepigeon/server/service/fcm/FcmService.java index 0ac5c36..66e48d8 100644 --- a/src/main/java/com/telepigeon/server/service/fcm/FcmService.java +++ b/src/main/java/com/telepigeon/server/service/fcm/FcmService.java @@ -11,7 +11,6 @@ @Component @RequiredArgsConstructor public class FcmService { - private final FirebaseMessaging firebaseMessaging; public void send( final String fcmToken, @@ -19,7 +18,7 @@ public void send( ){ Message message = createMessage(fcmToken, fcmMessageDto); try{ - firebaseMessaging.send(message); + FirebaseMessaging.getInstance().send(message); } catch (FirebaseMessagingException e){ throw new BusinessException(BusinessErrorCode.FCM_SERVER_ERROR); } From 42d9dc67c6deaef10c41dbaec06bfaa0414e6e5d Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Wed, 5 Jun 2024 22:27:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20#62=20firebaseconfig=20=EC=88=98?= =?UTF-8?q?=EC=A0=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/telepigeon/server/config/FirebaseConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telepigeon/server/config/FirebaseConfig.java b/src/main/java/com/telepigeon/server/config/FirebaseConfig.java index 82401e8..2e4fb86 100644 --- a/src/main/java/com/telepigeon/server/config/FirebaseConfig.java +++ b/src/main/java/com/telepigeon/server/config/FirebaseConfig.java @@ -16,10 +16,10 @@ @Configuration public class FirebaseConfig { @PostConstruct - public void firebaseApp() { + public void init() { if (!FirebaseApp.getApps().isEmpty()) { log.info("FirebaseApp already initialized"); - FirebaseApp.getInstance(); + return; } try { FileInputStream aboutFirebaseFile = new FileInputStream("src/main/resources/firebase.json");