我在Spring Boot应用程序中使用了来自不同项目的不同Firebase配置。
因此,在启动应用程序时,我注册了多个FirebaseApp
List<Location> locations = locationService.findAllLocations();
for (Location l : locations) {
if(l.getFirebaseConfigFile() != null) {
initializeFirebaseApp(l);
}
}
private void initializeFirebaseApp(Location location) throws IOException {
FileInputStream inputStream = new FileInputStream(configDir + location.getFirebaseConfigFile());
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(inputStream))
.build();
try {
FirebaseApp.initializeApp(options, location.getReferral() + "_app");
} catch (IllegalStateException e) {
logger.error("Config already exists " + FirebaseApp.getInstance(location.getReferral() + "_app").getName());
}
}
通过这种方式注册FirebaseApp进行定位。
现在,当我需要发送推送通知时,应该以这种方式调用正确的FirebaseApp实例
FirebaseApp app = FirebaseApp.getInstance(notification.getLocation().getReferral() + "_app");
String response = FirebaseMessaging.getInstance(app).sendAsync(message).get();
但是我得到了这个例外
java.util.concurrent.ExecutionException: com.google.firebase.messaging.FirebaseMessagingException: Requested entity was not found.
Caused by: com.google.api.client.http.HttpResponseException: 404 Not Found
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"errors": [
{
"message": "Requested entity was not found.",
"domain": "global",
"reason": "notFound"
}
],
"status": "NOT_FOUND"
}
}
似乎没有找到实例...这是在单个应用程序中管理多个Firebase项目的正确方法吗?