无法实例化提供程序 org.springframework.cloud.cloudfoundry.CloudFoundryConnector

Provider org.springframework.cloud.cloudfoundry.CloudFoundryConnector could not be instantiated

我正在开发将部署到 cloudfoundry 的 grails 2.5.3 应用程序。该应用程序绑定了很少的服务,为了获取这些服务的值,我使用了两个连接器:

//s3 service connector
compile ("org.cloudfoundry.community:spring-cloud-s3-service-connector:1.0.0") {
    excludes "aws-java-sdk", 'slf4j-api', 'slf4j-log4j12', 'slf4j'
}     
//sso service connector
compile (group: 'io.pivotal.spring.cloud', name: 'spring-cloud-sso-connector', version: '1.1.0.RELEASE') {
    excludes 'slf4j-api', 'slf4j-log4j12', 'slf4j'
}

当我同时使用这两个时,我的应用程序出现错误:

org.springframework.cloud.CloudConnector: Provider org.springframework.cloud.cloudfoundry.CloudFoundryConnector could not be instantiated

Caused by: java.lang.NoSuchMethodError: org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator.(Lorg/springframework/cloud/cloudfoundry/Tags;[Ljava/lang/String;)V at io.pivotal.spring.cloud.SsoServiceInfoCreator.(SsoServiceInfoCreator.java:11)

我认为错误的发生是因为这些服务中的每一个在 META-INF 下都有一个 services 文件夹,当同时使用这两个服务时显然只选择了一个。

两者的 META-INF/services 文件夹都在这里:

SSO 连接器:https://github.com/pivotal-cf/spring-cloud-sso-connector/tree/master/src/main/resources/META-INF/services

S3 连接器:https://github.com/cloudfoundry-community/spring-cloud-s3-service-connector/tree/master/src/main/resources/META-INF/services

我不确定如何解决这个错误。我尝试了各种组合,但 none 似乎有效。

更新

我添加了与此相关的第二个问题

类路径上有多个连接器扩展库很常见,每个库都有自己的 META-INF/services。这应该不是问题。

在您的 other question 中,您有:

compile ("org.cloudfoundry.community:spring-cloud-s3-service-connector:1.0.0") {
    excludes "aws-java-sdk", 'slf4j-api', 'slf4j-log4j12', 'slf4j'
}
//dependency tree shows 
+--- org.cloudfoundry.community:spring-cloud-s3-service-connector:1.0.0
|    \--- org.springframework.cloud:spring-cloud-cloudfoundry-connector:1.0.0.RELEASE
|         \--- org.springframework.cloud:spring-cloud-core:1.0.0.RELEASE
|    \--- org.hamcrest:hamcrest-all:1.3

compile (group: 'io.pivotal.spring.cloud', name: 'spring-cloud-sso-connector', version: '1.1.0.RELEASE') {
    excludes 'slf4j-api', 'slf4j-log4j12', 'slf4j', 'spring-cloud-starter-oauth2'
}
//dependency tree shows
+--- io.pivotal.spring.cloud:spring-cloud-sso-connector:1.1.0.RELEASE
|    \--- org.springframework.cloud:spring-cloud-spring-service-connector:1.1.1.RELEASE
|         \--- org.springframework.cloud:spring-cloud-core:1.1.1.RELEASE
|    \--- org.springframework.cloud:spring-cloud-cloudfoundry-connector:1.1.1.RELEASE

这表明 spring-cloud-s3-service-connector:1.0.0 传递依赖于 spring-cloud-core:1.0.0.RELEASE,而 spring-cloud-sso-connector:1.1.0.RELEASE 依赖于 spring-cloud-core:1.1.1.RELEASE。构建系统只会引入 spring-cloud-core 的一个版本,看起来 spring-cloud-core:1.0.0.RELEASE 是实际引入的版本,而 spring-cloud-sso-connector 与旧版本不兼容。

Maven Central 中有 spring-cloud-s3-service-connector:1.1.0,请尝试升级到该版本。