Firebase - Spring Boot 연동📦 Database/Firebase2023. 4. 22. 01:22
Table of Contents
💡 Firebase Spring Boot 연동
사전 준비사항
- Firebase 프로젝트 & Cloud Firestore 생성
- Firebase 프로젝트 설정 - 서비스 계정 - 새 비공개 키 생성 - json 파일 Spring resources 디렉터리로 이동
Dependency 등록
implementation group: 'com.google.firebase', name: 'firebase-admin', version: '8.1.0'
Spring Boot 설정
// FirebaseConfig.kt
@Service
@Configuration
class FirebaseConfig {
@Value("\${firebasePath}")
private val firebaseFilePath: String? = null
@PostConstructor
fun init() {
try {
val stream = Thread.currentThread().contextClassLoader.getResourceAsStream(firebaseFilePath)
val options = FirebaseOptions.builder()
.setCredentials(GoogleGredentials.fromStream(stream))
.setDatabaseUrl("https://~~.com/")
.build()
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options)
}
} catch (e: Exception) {
log.error("FIREBASE-001 : Firebase Initialize Failed")
throw Exception("", HttpStatus.EXPECTED_FAILED)
}
}
}
'📦 Database > Firebase' 카테고리의 다른 글
FCM HTTP -> HTTP v1 Migration (2) | 2023.04.27 |
---|---|
FCM (Firebase Cloud Message) (0) | 2023.04.26 |
Firebase 란? (0) | 2023.04.02 |
@신건우 :: 우주먼지
열심히 살고 싶은 사람의 메모장
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!