java - 在类路径资源中定义名称为“googleCredentials”的 bean 创建错误
问题描述
我正在尝试部署一个连接到 MySQL 数据库的宁静的 spring 应用程序。我将它部署在 gcp appengine 中,数据库也是一个 gcp sql 实例。我已经在我的机器上本地测试了我的代码,并且应用程序完美地连接到了 sql 实例。但是,当我尝试在 appengine 中运行应用程序时,我得到了 FileNotFoundException。我已经对我的 pom 文件进行了必要的补充。完整的错误是
2020-05-18 17:33:03 default[1] 2020-05-18 17:33:03.364 INFO 10 --- [onnection adder] c.google.cloud.sql.mysql.SocketFactory : Using GAE Unix Sockets
2020-05-18 17:33:05 default[1] 2020-05-18 17:33:05.153 INFO 10 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJt
aPlatform]
2020-05-18 17:33:05 default[1] 2020-05-18 17:33:05.179 INFO 10 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-18 17:33:06 default[1] 2020-05-18 17:33:06.703 INFO 10 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.117 WARN 10 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.bea
ns.factory.BeanCreationException: Error creating bean with name 'googleCredentials' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/core/GcpContextAutoConfiguration.class]: Bean instantiation via factory met
hod failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.google.api.gax.core.CredentialsProvider]: Factory method 'googleCredentials' threw exception; nested exception is java.io.
FileNotFoundException: src/main/resources/pigeon-276916-a62807e029a3.json (No such file or directory)
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.118 INFO 10 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.121 INFO 10 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.127 INFO 10 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.167 INFO 10 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.176 INFO 10 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.204 INFO 10 --- [ main] ConditionEvaluationReportLoggingListener :
2020-05-18 17:33:07 default[1]
2020-05-18 17:33:07 default[1] Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-05-18 17:33:07 default[1] 2020-05-18 17:33:07.218 ERROR 10 --- [ main] o.s.boot.SpringApplication : Application run failed
2020-05-18 17:33:07 default[1]
2020-05-18 17:33:07 default[1] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'googleCredentials' defined in class path resource [org/springframework/cloud/gcp/autoconfigure/core/GcpContextAutoC
onfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.google.api.gax.core.CredentialsProvider]: Factory method 'googleCre
dentials' threw exception; nested exception is java.io.FileNotFoundException: src/main/resources/pigeon-276916-a62807e029a3.json (No such file or directory) at org.springframework.beans.factory.support.ConstructorResolver.instantiat
e(ConstructorResolver.java:656) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:484) ~[spring-beans-5.2.6.R
ELEASE.jar!/:5.2.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEAS
E] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE] at org.springframework.bean
s.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapabl
eBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
我已经确定它pigeon-276916-a62807e029a3.json
确实存在于位置spring-backend/src/main/resources/pigeon-276916-a62807e029a3.json
,并且在我的 application.properties 文件中被引用为spring.cloud.gcp.credentials.location=file:src/main/resources/pigeon-276916-a62807e029a3.json
解决方案
正如 OP @Chadley Maggott 评论的那样,对此的修复只是注释此身份验证方法的行,因为这仅用于本地环境。当此解决方案部署到应用引擎时,这将使用为此应用引擎服务配置的服务帐户
推荐阅读
- javascript - wavesurfer.js 过滤器未按预期工作 [需要帮助]
- google-apps-script - 谷歌表时间戳“矩阵”
- django - 为什么 django 认为这些值不同?
- bash - 如何在 sudoers.d 文件中添加 DEBIAN_FRONTEND=noninteractive?
- c# - 执行 com.android.build.gradle.internal.tasks.workers$actionfacade 时发生故障 详情见控制台
- php - 使用 php-fpm 时应该阻止 9000 端口吗?
- javascript - React 保持不超过一个数组元素的状态
- sql - 视图返回空白(使用子查询过滤余额列)
- jdbc - 带有 ResultSet 的 Lambda 表达式
- javascript - 如何在 background.js 中监听 Chrome 窗口的控制台日志消息?