【发布时间】:2020-12-14 13:55:30
【问题描述】:
我在我的 Spring Boot 应用程序中使用了 firebase admin sdk。 (API 应用)
当我在 intelliJ 本地运行时,它工作正常。但是当部署在 tomcat 中时,它给了我 NPE。
在 Springboot 应用中
public static void main(String[] args) {
SpringApplication.run(InfanoApplication.class, args);
try {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
File file = new File(classloader.getResource("firebase2.json").getFile());
logger.info("FILE PATH : " + file.getAbsolutePath());
FileInputStream serviceAccount = new FileInputStream(file.getAbsolutePath());
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl(FB_BASE_URL)
.build();
firebaseApp = FirebaseApp.initializeApp(options);
logger.info("FIREBASE NAME : "+firebaseApp.getName());
} catch (IOException e) {
e.printStackTrace();
}
}
在 API 代码中
userRecord = FirebaseAuth.getInstance(InfanoApplication.firebaseApp).getUserByPhoneNumber(mobile);
错误:
java.lang.NullPointerException
at com.google.firebase.ImplFirebaseTrampolines.getService(ImplFirebaseTrampolines.java:62)
at com.google.firebase.auth.FirebaseAuth.getInstance(FirebaseAuth.java:101)
谁能帮忙解决这个问题。提前谢谢你。
【问题讨论】:
-
NPE 抱怨的 null 是什么?
-
@DougStevenson FirebaseAuth.getInstance 正在返回 null
标签: java firebase spring-boot firebase-authentication firebase-admin