I am trying make firebase auth and spring boot work for my app
here is my Application.java
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.reactive.function.client.WebClient;
import java.io.IOException;
@SpringBootApplication
@EnableScheduling
public class Application {
public static final Logger logger = LoggerFactory.getLogger("com.qmexpress");
static String FB_BASE_URL="https://qm-tracker-backend.firebaseio.com";
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
try {
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(new ClassPathResource("/qm-tracker-backend-firebase-adminsdk-wowh8-d8b0c278a7.json").getInputStream()))
.setDatabaseUrl(FB_BASE_URL)
.build();
FirebaseApp.initializeApp(options);
} catch (IOException e) {
e.printStackTrace();
}
}
@Bean
public WebClient webClient() {
return WebClient.create();
}
}
After I run app I get this message
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: FirebaseApp name [DEFAULT] already exists!
at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:227)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:218)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:205)
at com.qmexpress.Application.main(Application.java:37)
... 6 more