1212
1313import javax .annotation .PostConstruct ;
1414import java .io .ByteArrayInputStream ;
15+ import java .io .IOException ;
1516import java .io .InputStream ;
1617import java .nio .charset .StandardCharsets ;
1718import java .util .List ;
2122public class FCMConfig {
2223
2324 @ Value ("${firebase.config}" )
24- private String configFile ;
25+ private ClassPathResource fcmServiceKey ;
2526
2627 @ Value ("${firebase.scope}" )
2728 private String scope ;
@@ -38,12 +39,11 @@ public void initialize() {
3839// // ByteArrayInputStream을 사용하여 바이트 배열을 InputStream으로 변환
3940// InputStream inputStream = new ByteArrayInputStream(byteArray);
4041
41- ClassPathResource resource = new ClassPathResource (configFile );
42- InputStream inputStream = resource .getInputStream ();
42+ System .out .println (fcmServiceKey );
4343
4444 // Service Account를 이용하여 Fireabse Admin SDK 초기화
4545 FirebaseOptions options = FirebaseOptions .builder ()
46- .setCredentials (GoogleCredentials .fromStream (inputStream ).createScoped (List .of (scope )))
46+ .setCredentials (GoogleCredentials .fromStream (fcmServiceKey . getInputStream () ).createScoped (List .of (scope )))
4747 .build ();
4848
4949 if (FirebaseApp .getApps ().isEmpty ()) {
@@ -55,4 +55,10 @@ public void initialize() {
5555 throw new ApplicationException (ErrorCode .FAILED_FCM_INIT );
5656 }
5757 }
58+
59+ private String readResourceAsString (ClassPathResource resource ) throws IOException {
60+ try (InputStream inputStream = resource .getInputStream ()) {
61+ return new String (inputStream .readAllBytes (), StandardCharsets .UTF_8 );
62+ }
63+ }
5864}
0 commit comments