【发布时间】:2020-06-11 14:17:44
【问题描述】:
我遵循official 文档来实现这一点。但我仍然面临问题。我正在做春季启动项目。下面是我的代码,
@Configuration
public class FirebaseConfiguration {
// database url, other urls
// other codes...
@Value(value = "classpath:google-credentials.json")
private Resource gservicesConfig;
@Bean
public FirebaseApp provideFirebaseOptions() throws IOException {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream((gservicesConfig.getInputStream())))
.setDatabaseUrl(databaseUrl)
.setStorageBucket(storageUrl)
.build();
return FirebaseApp.initializeApp(options);
}
}
我还按照以下官方文档添加了配置
1.创建 Config Vars 键 GOOGLE_CREDENTIALS 并按原样粘贴服务帐户凭据 JSON 文件的内容。 2.在 Config Vars GOOGLE_APPLICATION_CREDENTIALS 下创建一个键,并将值设置为 google-credentials.json。
还添加了https://github.com/elishaterada/heroku-google-application-credentials-buildpack.git buildpack。但在日志中我遇到了以下问题。
Caused by: java.io.FileNotFoundException: class path resource [google-credentials.json] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
at com.read.bible.service.config.FirebaseConfiguration.provideFirebaseOptions(FirebaseConfiguration.java:35) ~[classes!/:na]
at com.read.bible.service.config.FirebaseConfiguration$$EnhancerBySpringCGLIB$$93cb42d.CGLIB$provideFirebaseOptions$0(<generated>) ~[classes!/:na]
【问题讨论】:
标签: firebase spring-boot heroku google-api