Skip to content

Commit 5d1b6b7

Browse files
committed
refactor: firebase key 경로 수정
1 parent dbd3dcd commit 5d1b6b7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/go/alarm/fcm/config/FCMConfig.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,34 @@
66
import com.google.firebase.messaging.FirebaseMessaging;
77
import java.io.IOException;
88
import java.io.InputStream;
9+
10+
import org.springframework.beans.factory.annotation.Value;
911
import org.springframework.context.annotation.Bean;
1012
import org.springframework.context.annotation.Configuration;
11-
import org.springframework.core.io.FileSystemResource;
13+
import org.springframework.core.io.ClassPathResource;
1214
import org.springframework.core.io.Resource;
1315

1416
@Configuration
1517
public class FCMConfig {
18+
@Value("${fcm.service-account-file}")
19+
private String firebaseKeyPath;
1620

1721
@Bean
1822
public FirebaseApp firebaseApp() throws IOException {
19-
// 프로젝트 파일과 동일한 디렉토리에 있는 firebase_service_key.json 파일 경로
20-
String filePath = "./firebase_service_key.json";
2123

22-
// FileSystemResource를 사용하여 파일 시스템에서 리소스를 로드
23-
Resource resource = new FileSystemResource(filePath);
24+
Resource resource = new ClassPathResource(firebaseKeyPath.replace("file:", " "));
2425
InputStream serviceAccount = resource.getInputStream();
2526

2627
FirebaseOptions options = FirebaseOptions.builder()
2728
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
2829
.build();
2930

30-
return FirebaseApp.initializeApp(options);
31+
// 이미 초기화되었는지 확인하여 중복 초기화를 방지
32+
if (FirebaseApp.getApps().isEmpty()) {
33+
return FirebaseApp.initializeApp(options);
34+
} else {
35+
return FirebaseApp.getInstance();
36+
}
3137
}
3238

3339
@Bean

0 commit comments

Comments
 (0)