Firebase - Spring Boot 연동

2023. 4. 22. 01:22·📦 Database/Firebase

💡 Firebase Spring Boot 연동

사전 준비사항

Firebase 프로젝트 생성

  • 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
'📦 Database/Firebase' 카테고리의 다른 글
  • FCM HTTP -> HTTP v1 Migration
  • FCM (Firebase Cloud Message)
  • Firebase 란?
신건우
신건우
조용한 개발자
  • 신건우
    우주먼지
    신건우
  • 전체
    오늘
    어제
    • 분류 전체보기 (422)
      • 📘 Frontend (71)
        • Markup (1)
        • Style Sheet (2)
        • Dart (8)
        • Javascript (12)
        • TypeScript (1)
        • Vue (36)
        • React (2)
        • Flutter (9)
      • 📘 Backend (143)
        • Java (34)
        • Concurrency (19)
        • Reflection (1)
        • Kotlin (29)
        • Python (1)
        • Spring (42)
        • Spring Cloud (5)
        • Message Broker (5)
        • Streaming (2)
        • 기능 개발 (5)
      • 💻 Server (6)
        • Linux (6)
      • ❌ Error Handling (11)
      • 📦 Database (62)
        • SQL (31)
        • NoSQL (2)
        • JPQL (9)
        • QueryDSL (12)
        • Basic (4)
        • Firebase (4)
      • ⚙️ Ops (57)
        • CS (6)
        • AWS (9)
        • Docker (8)
        • Kubernetes (13)
        • MSA (1)
        • CI & CD (20)
      • 📚 Data Architect (48)
        • Data Structure (10)
        • Algorithm (8)
        • Programmers (17)
        • BaekJoon (5)
        • CodeUp (4)
        • Design Pattern (4)
        • AI (0)
      • ⚒️ Management & Tool (8)
        • Git (7)
        • IntelliJ (1)
      • 📄 Document (10)
        • Project 설계 (6)
        • Server Migration (3)
      • 📄 책읽기 (2)
        • 시작하세요! 도커 & 쿠버네티스 (2)
      • 🎮 Game (4)
        • Stardew Vally (1)
        • Path of Exile (3)
  • 블로그 메뉴

    • 링크

      • Github
    • 공지사항

    • 인기 글

    • 태그

      React #Markdown
      GStreamer #Pipeline
      Lock #Thread #Concurrency
    • 최근 댓글

    • 최근 글

    • hELLO· Designed By정상우.v4.10.0
    신건우
    Firebase - Spring Boot 연동
    상단으로

    티스토리툴바