I tried FileNotFoundException and try, catch but did not help. I think problem is here
InputStream serviceAccount = new FileInputStream("/src/main/resources/static/FirebaseAdminSDKJava.json");
Full class source code:
package uz.xose.webapp;
import java.io.FileInputStream;
import java.io.InputStream;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.cloud.FirestoreClient;
@RestController
public class HelloController {
InputStream serviceAccount = new FileInputStream("/src/main/resources/static/FirebaseAdminSDKJava.json");
GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp.initializeApp(options);
Firestore db = FirestoreClient.getFirestore();
@RequestMapping("/")
public String index() {
return "This is the index!\n";
}
@RequestMapping("/hello")
public String index2() {
return "Hello, World!\n";
}
}
I am using Spring framework.
FirebaseAdminSDKJava.json located: src -> main -> resources -> static -> FirebaseAdminSDKJava.json