GithubHelp home page GithubHelp logo

Comments (10)

scottfrederick avatar scottfrederick commented on May 24, 2024

AbstractCloudConfig does import service-specific classes, but the dependencies on the libraries that provide these classes are marked optional in the build file. This means that these dependencies are not transitive, and apps or libraries that use Spring Cloud Connectors do not automatically have all these libraries as dependencies. See the Maven documentation for more details.

Does the fact that these dependencies are not transitive remove your concerns here?

from spring-cloud-connectors.

scottfrederick avatar scottfrederick commented on May 24, 2024

@gauthierj Any feedback on response above?

from spring-cloud-connectors.

davidehringer avatar davidehringer commented on May 24, 2024

I think the problem is that because they are imported you get a NoClassDefFound if you don't include them as dependencies even if you aren't using them. If you have something like:

public class CloudConfig extends AbstractCloudConfig {

    // access some services, none of which are rabbit, redis, or mongo
}

You still have to include rabbit, redis, and mongo related dependencies even though you don't use them in your app.

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>1.6.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit</artifactId>
            <version>1.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>1.3.4.RELEASE</version>
        </dependency>

Otherwise you get NoClassDefFoundExceptions.

from spring-cloud-connectors.

gauthierj avatar gauthierj commented on May 24, 2024

Thanks @davidehringer that's exactly my problem.

Sorry for the late answer @scottfrederick, but I'm not truly working on that currently.

from spring-cloud-connectors.

scottfrederick avatar scottfrederick commented on May 24, 2024

@davidehringer and @gauthierj Sorry for the back-and-forth on this, but I think we are seeing different things and I'm not sure what's causing the differences.

Here are several sample projects that use Spring Cloud Connectors, including AbstractCloudConfig, but only include the dependencies they actually use in the app:

Spring Music:

Spring Sendgrid:

rabbitmq-cloudfoundry-samples:

Can someone share a project that demonstrates the NoClassDefFoundException behavior so we can figure out what's different between these projects?

from spring-cloud-connectors.

davidehringer avatar davidehringer commented on May 24, 2024

@scottfrederick not a problem.
Here is an example project that demonstrates the issue: https://github.com/davidehringer/spring-cloud-connector-dependency-issue

from spring-cloud-connectors.

ramnivas avatar ramnivas commented on May 24, 2024

@davidehringer What's the version of JDK you are using?

from spring-cloud-connectors.

davidehringer avatar davidehringer commented on May 24, 2024

1.7.0_67

from spring-cloud-connectors.

jhiemer avatar jhiemer commented on May 24, 2024

Having exactly the same issue in three projects.

from spring-cloud-connectors.

scottfrederick avatar scottfrederick commented on May 24, 2024

Fixed in 625040c.

The reason that this problem was hard to nail down was that (per my testing anyway) the NoClassDefFoundException would only be triggered when the @Configuration class that extends AbstractCloudConfig was nested within a Spring Boot main class (or possibly nested in any @Configuration or @Component class). The exception would not get thrown if the @Configuration class was a top-level class. There may be other edge cases, but that explains why the problem didn't happen in all the (older, mostly non-Boot) projects listed in the comment above, but happened in many newer (I presume Boot) projects.

Moving the ServiceConnectionFactory class (which is where the DataSource, MongoDB, Redis, RabbitMQ dependencies come from) from an inner class of AbstractCloudConfig to a top-level class, and making AbstractCloudConfig depend on an interface instead of this concrete class, change the way Spring inspects these classes for configuration, and prevents the invocation of the Java refection API that was triggering the NoClassDefFoundException.

from spring-cloud-connectors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.