【问题标题】:Spring boot firebase admin sdk setup - Cannot resolve symbolsSpring boot firebase admin sdk setup - 无法解析符号
【发布时间】:2018-04-10 19:16:18
【问题描述】:

我正在使用本指南在我的 spring-boot java 应用程序上初始化 firebase admin sdk:https://firebase.google.com/docs/admin/setup

我已经包含了正确的 maven 依赖项

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>5.9.0</version>
</dependency>

我正在尝试使用他们提供的代码 sn-p 进行初始化,但是当我导入 firebase 库时,没有解析任何符号(firebase、auth、FirebaseOptions、GoogleCredentials、FirebaseApp)。

import java.io.FileInputStream;
import com.google.firebase.*;
import com.google.auth.oauth2.GoogleCredentials;

import org.springframework.context.annotation.Configuration;

@Configuration
public class FirebaseAdminConfig {
    FileInputStream serviceAccount = new 
FileInputStream("path/to/firebase/credentials/");
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredentials(GoogleCredentials.fromStream(serviceAccount))
            .setDatabaseUrl("link to database")
            .build();
FirebaseApp.initializeApp(options);
}

我是否缺少导入语句?是否需要一些额外的配置?

【问题讨论】:

  • 您是否更新了新导入的依赖项?

标签: java maven spring-boot firebase-admin


【解决方案1】:

在您的 FirebaseAdminConfig 类中,您已直接粘贴了 sn-p。需要先创建一个方法,否则会出现编译错误。

@Configuration
public class FireBaseConfig{
@Bean
    FirebaseApp createFireBaseApp() throws IOException {
    FileInputStream serviceAccount =
            new FileInputStream("pathtojson.json");

    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredentials(GoogleCredentials.fromStream(serviceAccount))
            .setDatabaseUrl("url")
            .build();

  return  FirebaseApp.initializeApp(options);
}

}

【讨论】:

    【解决方案2】:

    您也可以在Application的主类中这样做

    public static void main(String[] args) throws IOException {
        FileInputStream serviceAccount = new FileInputStream("src/main/resources/credential.json");
        @SuppressWarnings("deprecation")
        FirebaseOptions options = new FirebaseOptions.Builder()
                .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                .build();
        FirebaseApp.initializeApp(options);
        SpringApplication.run(MarketingDashboardApplication.class, args);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 2019-09-24
      • 2016-10-06
      • 1970-01-01
      相关资源
      最近更新 更多