์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- GitHub
- HTML์ ๋ฌธ
- ๋ฐฑ์ค
- ๋ฏธ๊ตญ์ฌํ #๋ฏธ๊ตญ์ ๊ตญ์ฌํ
- ๋์ ํ ๋น๋ฒ
- C++
- 2579
- ๊ฐ๋ฐ์์ค๋น #์ปดํจํฐ๊ณตํ๊ณผ
- html #css์ ๋ฌธ #visual studio
- Today
- Total
๐๊ฐ๋ฐ๊ณผ ์ผ์ (โงโโฆ)๏พ
[Spring, firebase] firebase ๋ด DB ์ฐ๋ํด๋ณด์. ๋ณธ๋ฌธ
1. ์์กด์ฑ ์ถ๊ฐ
gradle
implementation group: 'com.google.firebase', name: 'firebase-admin', version: '8.1.0'
maven
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>8.1.0</version>
</dependency>
ํน์ ๋ฒ์ ์ด ํ์ํ๋ค๋ฉด mvnrepository ๊ณต์ ์ฌ์ดํธ๋ฅผ ํ์ธํด๋ณด์

https://mvnrepository.com/artifact/com.google.firebase/firebase-admin
๋ฒ์ ๋ณ๋ก ์ค์ ์ด ๊ฐ๋ฅํจ.
2. Firebase ์ฝ์ ๋ด ์ค์ ์งํ
๊ธฐ์กด์ ๊ตฌ์ฑํด๋์ ํ์ด์ด๋ฒ ์ด์ค ํ๋ก์ ํธ์ ๋ค์ด๊ฐ ํ๊ฒฝ์ค์ >ํ๋ก์ ํธ ์ค์ ์ ๋ค์ด๊ฐ๋ค.

์ ๋น๊ณต๊ฐ ํค๋ฅผ ์์ฑํ๋ค. ๊ทธ๋ฌ๋ฉด json ํ์ผ์ ๋ค์ด ๋ฐ์ ์ ์๋ค.
ํด๋น ๋ฐ์ดํฐ๋ฅผ ํ๋ก์ ํธ ํด๋ > resources > config์ ์ ์ฅํ๋ค.

3. FirebaseConfig.java ์์ฑ
firebase์ ์ ๊ทผ ํ ์ ์๋ ํด๋์ค firebaseConfig๋ฅผ ์ ์ธํ์ฌ ์ ๊ทผ ๊ฐ๋ฅํ๋๋ก ํ์ต๋๋ค.

@Configuration
public class FirebaseConfig {
private String firebaseSdkPath = "./HHBE/src/main/resources/config/firebaseKey.json";
private FirebaseApp firebaseApp;
@Bean
public FirebaseAuth firebaseAuth() throws IOException {
//read firebaseKey.json
Resource resource = new ClassPathResource(firebaseSdkPath);
FileInputStream fis = new FileInputStream(resource.getFile());
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(fis))
.build();
firebaseApp = FirebaseApp.initializeApp(options,"gnd");
//FirebaseApp.initializeApp(options);
return FirebaseAuth.getInstance(firebaseApp);
}
}
ํด๋น ํด๋์ค์ Firebase์ ๋ณด json ํ์ผ์ ๋ถ๋ฌ์ ์ด๋ฅผ ํ์ฉํด์ Google credit์ ๋ฐ์์ ์ธ๊ฐ ์ธ์คํด์ค๋ฅผ ๋ฐ์ ์ ์๋๋ก ํฉ๋๋ค.