我最近将Spring Boot应用程序部署到Elastic Beanstalk。 春天开始没有错误。
我们正在使用Firebase进行用户身份验证。在本地机器上,甚至在其他外部主机上,Firebase操作都可以正常运行,但在EBS上却不能。
如果我阅读日志:
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:164) ~[firebase-admin-6.3.0.jar!/:na]
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:135) ~[firebase-admin-6.3.0.jar!/:na]
at com.google.firebase.auth.FirebaseAuth.getInstance(FirebaseAuth.java:100) ~[firebase-admin-6.3.0.jar!/:na]
at com.bodymate.springend.mvc.service.FirebaseService.validateToken(FirebaseService.java:15) ~[classes!/:1.0-SNAPSHOT]
at com.bodymate.springend.mvc.controller.UserController.register(UserController.java:66) ~[classes!/:1.0-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]...
这是我的Firebase配置:
@Configuration
public class FirebaseConfig {
@PostConstruct
public void init() {
FirebaseOptions options;
try {
FileInputStream serviceAccount = new FileInputStream("src/main/resources/google-services.json");
options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.build();
} catch (java.io.IOException e) {
e.printStackTrace();
return;
}
FirebaseApp.initializeApp(options);
}
}
失控的地方:
@Service
public class FirebaseService {
public FirebaseToken validateToken(String token) throws InterruptedException, ExecutionException, InvalidFirebaseTokenException {
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdTokenAsync(token).get();
if( decodedToken != null && decodedToken.getUid() != null && !decodedToken.getUid().isEmpty()){
return decodedToken;
}else{
throw new InvalidFirebaseTokenException();
}
}
}
有人知道这里出了什么问题吗?
编辑
我正在使用mvn clean install
为EBS构建我的.jar文件。
此版本可能不包含“ google-services.json”吗?