Skip to content

Commit

Permalink
feat: fcm account key 접근 방식 변경(#84)
Browse files Browse the repository at this point in the history
- 기존에는 'classpath:~' 를 루트로 하는 경로를 이용해 fcm account key를 접근
- 배포시에 해당 경로를 인식하지 못해 리소스를 접근하지 못하는 에러 발생
- spring에서 제공하는 ClassPathResource를 이용하여 접근하는 방식으로 변경
  • Loading branch information
Minjae-An committed May 15, 2024
1 parent db8835b commit e31148f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions be/src/main/java/yeonba/be/config/FcmConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.FirebaseMessaging;
import java.io.FileInputStream;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ClassPathResource;

@Configuration
public class FcmConfig {

@Value("${FCM_ACCOUNT_KEY_PATH}")
private Resource accountKey;
private String fcmAccountKeyPath;

@Bean
public FirebaseMessaging firebaseMessaging() throws IOException {

FileInputStream serviceAccount = new FileInputStream(accountKey.getFile());
ClassPathResource resource = new ClassPathResource(fcmAccountKeyPath);

FirebaseOptions firebaseOptions = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setCredentials(GoogleCredentials.fromStream(resource.getInputStream()))
.build();

return FirebaseMessaging.getInstance(FirebaseApp.initializeApp(firebaseOptions));
Expand Down

0 comments on commit e31148f

Please sign in to comment.