Skip to content

Commit

Permalink
✨ 파이어베이스 자동 초기화 (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
semi-cloud committed Sep 18, 2022
1 parent 79d1a15 commit a660f86
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/com/tickettogether/global/fcm/FCMInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.tickettogether.global.fcm;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;

@Component
@Slf4j
public class FCMInitializer {

@Value("${fcm.certification}")
private String googleApplicationCredentials;

@PostConstruct
public void initialize() throws IOException {
ClassPathResource resource = new ClassPathResource(googleApplicationCredentials);
try (InputStream is = resource.getInputStream()){
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(is))
.build();

if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
log.info("FirebaseApp initialization complete");
}
}catch(Exception ex){
log.info(ex.getMessage());
}
}
}

0 comments on commit a660f86

Please sign in to comment.