【发布时间】:2020-01-30 00:09:04
【问题描述】:
如果我使用单个 Spring Cloud GCP 库,例如implementation("org.springframework.cloud:spring-cloud-gcp-starter-sql-postgresql:1.1.1.RELEASE") 和属性:spring.cloud.gcp.credentials.encoded-key= 用于凭据...一切正常。
但如果我还想说通过 implementation("org.springframework.cloud:spring-cloud-gcp-starter-pubsub:1.1.3.RELEASE") 将 pub/sub 添加到我的项目中,那么我会得到以下异常。
我试过了:
- 使用不同的 Java 版本 11 和 12
- 不同的Spring Cloud GCP库作为“第二”库
implementation("org.springframework.cloud:spring-cloud-gcp-starter:1.1.3.RELEASE")和implementation("org.springframework.cloud:spring-cloud-gcp-starter-logging:1.1.3.RELEASE") - 使用
spring.cloud.gcp.credentials.location代替spring.cloud.gcp.credentials.encoded-key - 使用管理员服务帐户确保不是 IAM 角色问题。
implementation("org.springframework.cloud:spring-cloud-gcp-starter:1.1.3.RELEASE") 和 implementation("org.springframework.cloud:spring-cloud-gcp-starter-logging:1.1.3.RELEASE")
只要我包含多个这些 Spring Cloud GCP 库,同样的 SocketFactory 错误就会出现。从文档中,它应该可以正常工作。第二个库应该只使用相同的凭据。
如果我恢复到单个库,那么它工作正常。
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties]: Factory method 'cloudSqlDataSourceProperties' threw exception; nested exception is java.lang.NoClassDefFoundError: com/google/cloud/sql/core/CoreSocketFactory
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 171 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/google/cloud/sql/core/CoreSocketFactory
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration.cloudSqlDataSourceProperties(GcpCloudSqlAutoConfiguration.java:209) ~[spring-cloud-gcp-autoconfigure-1.1.3.RELEASE.jar:1.1.3.RELEASE]
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$4f5495da.CGLIB$cloudSqlDataSourceProperties$0(<generated>) ~[spring-cloud-gcp-autoconfigure-1.1.3.RELEASE.jar:1.1.3.RELEASE]
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$4f5495da$$FastClassBySpringCGLIB$$58c2377.invoke(<generated>) ~[spring-cloud-gcp-autoconfigure-1.1.3.RELEASE.jar:1.1.3.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.cloud.gcp.autoconfigure.sql.GcpCloudSqlAutoConfiguration$CloudSqlDataSourcePropertiesConfiguration$$EnhancerBySpringCGLIB$$4f5495da.cloudSqlDataSourceProperties(<generated>) ~[spring-cloud-gcp-autoconfigure-1.1.3.RELEASE.jar:1.1.3.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 172 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.google.cloud.sql.core.CoreSocketFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
... 183 common frames omitted
我还在这里创建了一个 Github 问题:https://github.com/spring-cloud/spring-cloud-gcp/issues/1948
【问题讨论】:
标签: java spring-boot kotlin google-cloud-platform spring-cloud