问题描述
昨天我将我的 github 链接到了一个 azure 网络应用服务 我的 repo 使用 rest 请求构建,其中一些正在处理从基于 firestore 的数据库加载数据,我在 spring 附带的 tomcat 嵌入式服务器上的 localhost 上运行了所有这些 ,让 web 应用程序在空中运行,我的 post 请求从 firebase 获取资源,post 请求为我提供了一个内部 500 服务器,所以我检查应用程序洞察功能以检查我得到了什么异常
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:165)
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:136)
我的 fire base 初始化代码是:
package Model;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaSEOptions;
import org.springframework.stereotype.Service;
import javax.annotation.postconstruct;
import java.io.File;
import java.io.FileInputStream;
import java.util.Objects;
@Service
public class FBInitialize {
@postconstruct
public void initialize() {
try {
String fileName = "name of json file with Credential.json";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(Objects.requireNonNull(classLoader.getResource(fileName)).getFile());
FileInputStream serviceAccount = new FileInputStream(file);
FirebaSEOptions options = new FirebaSEOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://qr-database-my data base url")
.build();
FirebaseApp.initializeApp(options);
} catch (Exception e) {
e.printstacktrace();
}
}
我检查了日志,我确实收到了请求我只是收到此异常是任何人都遇到过 这个例外? 顺便说一下,在 initiazlizeApp 方法中,正在调用 getIntstance 方法。
编辑: 发现异常是从哪里抛出的:
public static FirebaseApp getInstance(@NonNull String name) {
synchronized(appsLock) {
FirebaseApp firebaseApp = (FirebaseApp)instances.get(normalize(name));
if (firebaseApp != null) {
return firebaseApp;
} else {
List<String> availableAppNames = getAllAppNames();
String availableAppNamesMessage;
if (availableAppNames.isEmpty()) {
availableAppNamesMessage = "";
} else {
availableAppNamesMessage = "Available app names: " + Joiner.on(",").join(availableAppNames);
}
String errorMessage = String.format("FirebaseApp with name %s doesn't exist. %s",name,availableAppNamesMessage);
throw new IllegalStateException(errorMessage);
}
}
}
解决方法
问题可能是github上的源代码版本。请检查 build.gradle
文件夹下的 android/app
文件。
添加以下行:
apply plugin:'com.google.gms.google-services'
相关帖子:
1. How to solve Exception Error: FirebaseApp with name [DEFAULT] doesn't exist?
2. FirebaseApp with name [DEFAULT] doesn't exist
,我与 maven 一起工作,我还发现它与带有 google 凭据位置的 json 文件有关,因为重新打包文件将根内容更改为 BOOT-INF,因此我将 json 文件内容放入字符串中并将其转换为 Inputstream,因此 Initializeapp 和 init 将是独立的,但仍然没有乐趣:(
新更新: 现在我得到了一个不同的例外,我认为它与安全有关
java.lang.IllegalStateException: Could not find TLS ALPN provider; no working netty-tcnative,Conscrypt,or Jetty NPN/ALPN available
agian 我正在使用 maven 而不是在 android 上工作