|
|
@@ -0,0 +1,42 @@
|
|
|
+package com.aitori.config;
|
|
|
+
|
|
|
+import com.google.auth.oauth2.GoogleCredentials;
|
|
|
+import com.google.firebase.FirebaseApp;
|
|
|
+import com.google.firebase.FirebaseOptions;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.boot.CommandLineRunner;
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+@Order(1)
|
|
|
+public class FireBaseConfig implements CommandLineRunner {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(String... args) throws Exception {
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init() throws IOException {
|
|
|
+ String serviceAccountKeyPath = "app-aitori-jp-firebase-adminsdk.json";
|
|
|
+ Resource resource = new ClassPathResource(serviceAccountKeyPath);
|
|
|
+ InputStream inputStream = resource.getInputStream();
|
|
|
+
|
|
|
+ //协议开放 克服握手错误
|
|
|
+ System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
|
|
|
+ log.info("协议开放成功:{}", System.getProperty("https.protocols"));
|
|
|
+ //firebase初始化
|
|
|
+ FirebaseOptions options = new FirebaseOptions.Builder()
|
|
|
+ .setCredentials(GoogleCredentials.fromStream(inputStream))
|
|
|
+ .setDatabaseUrl("https://app-aitori-jp.firebaseio.com/")//
|
|
|
+ .build();
|
|
|
+ FirebaseApp.initializeApp(options);
|
|
|
+ log.info("firebase初始化成功");
|
|
|
+ }
|
|
|
+}
|