-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79d1a15
commit a660f86
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/tickettogether/global/fcm/FCMInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
|