Skip to content

Commit

Permalink
[FEAT]/#70-FCMConfig 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed Mar 7, 2024
1 parent de44e4b commit 2f1def6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ out/
### VS Code ###
.vscode/
application.properties
treehouse-fcm-secretKey.json
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ dependencies {
// aws s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

//FCM
implementation 'com.google.firebase:firebase-admin:9.2.0'

runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/org/example/tree/global/config/FCMConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.example.tree.global.config;

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

import java.io.IOException;
import java.io.InputStream;

@Slf4j
@Configuration
public class FCMConfig {

@Value("${firebase.key-path}")
private String fcmKeyPath;

@PostConstruct
public void initialize() {
try {
final InputStream refreshToken = new ClassPathResource(fcmKeyPath).getInputStream();

final FirebaseOptions options = FirebaseOptions
.builder()
.setCredentials(GoogleCredentials.fromStream(refreshToken))
.build();

FirebaseApp.initializeApp(options);
log.info("Fcm Setting Completed");

} catch (final IOException e) {
throw new RuntimeException(e.getMessage());
}
}

}
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ cloud:
secret-key: ${SECRET_KEY}
#aws access key, secret key

firebase:
key-path: ${FIREBASE_KEY_PATH}
#firebase key path for push notification

---
#spring:
# config:
Expand Down

0 comments on commit 2f1def6

Please sign in to comment.