Provider org.springframework.cloud.cloudfoundry.Cl

2019-07-29 03:47发布

问题:

I am working on a grails 2.5.3 app that will be deployed to cloudfoundry. The app is bound with few services and in order to get the values for those services I use two connectors:

//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'
}

When I use both of these I get an error in my application:

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)

I believe the error is happening because each of these services have a services folder under META-INF and apparently only one is picked when both of these are used simultaneously.

The META-INF/services folder for both is here:

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

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

I'm not sure how to resolve this error. I've tried various combinations but none seem to work.

Update

I've added a second question that is related to this https://stackoverflow.com/questions/42976791/common-dependency-for-two-packages-gets-dropped-when-both-pages-are-used

回答1:

Having multiple Connector extension libs on the classpath is common, each with their own META-INF/services. This shouldn't be a problem.

In your other question, you have:

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

and

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

This shows that spring-cloud-s3-service-connector:1.0.0 transitively depends on spring-cloud-core:1.0.0.RELEASE, while spring-cloud-sso-connector:1.1.0.RELEASE depends on spring-cloud-core:1.1.1.RELEASE. The build system will only pull in one version of spring-cloud-core, and it appears that spring-cloud-core:1.0.0.RELEASE is the one that is actually getting pulled in and spring-cloud-sso-connector isn't compatible with that older version.

There is a spring-cloud-s3-service-connector:1.1.0 available in Maven Central, try upgrading to that version.