如果我使用单个Spring库,例如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,那么我将得到下面的例外情况。
我试过:
implementation("org.springframework.cloud:spring-cloud-gcp-starter-logging:1.1.3.RELEASE")
implementation("org.springframework.cloud:spring-cloud-gcp-starter:1.1.3.RELEASE")和spring.cloud.gcp.credentials.location而不是spring.cloud.gcp.credentials.encoded-key
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库,同样的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
发布于 2019-09-30 19:02:26
由于从Maven Central复制粘贴导入而没有检查版本,所以使用了不同版本的库。
使用的版本包括1.1.1.RELEASE和1.1.3.RELEASE。一次只应该使用其中的一个发行号。
重构代码以删除此错误的可能性:
implementation("org.springframework.cloud:spring-cloud-gcp-starter-sql-postgresql:$springCloudGCPVersion")
implementation("org.springframework.cloud:spring-cloud-gcp-starter-pubsub:$springCloudGCPVersion")
implementation("org.springframework.cloud:spring-cloud-gcp-dependencies:$springCloudGCPVersion")
implementation("org.springframework.cloud:spring-cloud-gcp-starter:$springCloudGCPVersion")https://stackoverflow.com/questions/58172262
复制相似问题