Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

azure web app loaded from github repo based on spring boot problem

yesterday i linked my github to an azure web app service my repo built with rest requests and some of them is working with loading data from firestore based databased , i ran it all on localhost on the tomcat embedded server that comes with spring ,got the web app in the air and my post request which getting resource from firebase , the post request got me an internal 500 server so i check the app insights feature to check what exception i get

java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. 
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:165)
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:136)

my init code for fire base is:

 package Model;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileInputStream;
import java.util.Objects;

@Service
public class FBInitialize {
    @PostConstruct
    public void initialize() {
        try {
            String fileName = "name of json file with Credential.json";
            ClassLoader classLoader = getClass().getClassLoader();
            File file = new File(Objects.requireNonNull(classLoader.getResource(fileName)).getFile());
            FileInputStream serviceAccount = new FileInputStream(file);
            FirebaseOptions options = new FirebaseOptions.Builder()
                    .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                    .setDatabaseUrl("https://qr-database-my data base url")
                    .build();
            FirebaseApp.initializeApp(options);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

i checked on the logs and i did got the request i just getting this exception is anyone ever encounter this exception ? by the way on initiazlizeApp method the getIntstance methood is being called.

Edit: found where the exception was thrown from :

public static FirebaseApp getInstance(@NonNull String name) {
            synchronized(appsLock) {
                FirebaseApp firebaseApp = (FirebaseApp)instances.get(normalize(name));
                if (firebaseApp != null) {
                    return firebaseApp;
                } else {
                    List<String> availableAppNames = getAllAppNames();
                    String availableAppNamesMessage;
                    if (availableAppNames.isEmpty()) {
                        availableAppNamesMessage = "";
                    } else {
                        availableAppNamesMessage = "Available app names: " + Joiner.on(", ").join(availableAppNames);
                    }
    
                    String errorMessage = String.format("FirebaseApp with name %s doesn't exist. %s", name, availableAppNamesMessage);
                    throw new IllegalStateException(errorMessage);
                }
            }
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem may be the source code version on github. Please check build.gradle file under android/app folder.

Add the following line:

apply plugin:'com.google.gms.google-services'

Related Posts:

1. How to solve Exception Error: FirebaseApp with name [DEFAULT] doesn't exist?

2. FirebaseApp with name [DEFAULT] doesn't exist


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...