Comments (10)
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.
@gauthierj Any feedback on response above?
from spring-cloud-connectors.
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.
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.
@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:
- several
AbstractCloudConfig
classes here: https://github.com/cloudfoundry-samples/spring-music/tree/master/src/main/java/org/cloudfoundry/samples/music/config/data - only JPA, Mongo and Redis dependencies, no RabbitMQ/AMQP: https://github.com/cloudfoundry-samples/spring-music/blob/master/build.gradle#L54-L113
Spring Sendgrid:
- just one
AbstractCloudConfig
class for e-mail configuration: https://github.com/cloudfoundry-samples/spring-sendgrid/blob/master/src/main/java/org/cloudfoundry/samples/email/config/app/AppCloudConfig.java - no Spring Data dependencies at all: https://github.com/cloudfoundry-samples/spring-sendgrid/blob/master/build.gradle#L49-L84
rabbitmq-cloudfoundry-samples:
- uses XML config to get a RabbitMQ connection: https://github.com/cloudfoundry-samples/rabbitmq-cloudfoundry-samples/blob/master/spring/src/main/webapp/WEB-INF/spring/servlet-context.xml#L16-L17
- only depends on Spring AMQP: https://github.com/cloudfoundry-samples/rabbitmq-cloudfoundry-samples/blob/master/spring/pom.xml#L29-L72
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.
@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.
@davidehringer What's the version of JDK you are using?
from spring-cloud-connectors.
1.7.0_67
from spring-cloud-connectors.
Having exactly the same issue in three projects.
from spring-cloud-connectors.
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)
- Critical CVE related to com.fasterxml.jackson.core:jackson-databind
- Redis Service Uris in Cloud Foundry do not contain user info, thus UriBasedServiceInfo throws exception HOT 1
- Support for reactive mongodb connection HOT 4
- Make it clear that Spring Cloud Connectors is in maintenance mode HOT 1
- CVE-2019-12814 related to com.fasterxml.jackson.core:jackson-databind HOT 5
- Redis connector has a race condition with Spring Boot 2.x
- PropertyMaskingContextInitializer prevents configuration of "keys-to-sanitize" HOT 1
- Maintenence mode? HOT 1
- Update spring-cloud-cloudfoundry-connector Jackson dependencies from 2.9.1 to latest version 2.10.0 HOT 1
- New release for jacksonVersion = "2.10.0" ? HOT 4
- maxWaitTime of PoolConfig is not used HOT 4
- spring-cloud-connector fails to detect MongoDB service broker (DNS Seedlist Connection Format) in PCF HOT 1
- MailSenderCreator Create Method accepts the ServiceConnectorConfig object, but does not set the config property to JavaMailSender HOT 1
- spring-cloud-cloudfoundry-connector 2.0.7.RELEASE can't be used in a modular Java 11 project HOT 2
- Mongo Connector doesn't work with Spring Boot 2.4.1? HOT 7
- CVE-2020-25649 - related to com.fasterxml.jackson.core:jackson-databind inspring-cloud-cloudfoundry-connector-2.0.7.RELEASE.jar HOT 7
- Vulnerable version of Jackson-Databind with Spring-Cloud-cloudfoundry-connector HOT 1
- HiKari datasource in spring cloud (CF) failed to set PG related connection properties HOT 2
- java.lang.IllegalAccessError: failed to access class com.mongodb.client.internal.MongoClientDelegate from class com.mongodb.Mongo HOT 2
- Redis connection pool config not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-connectors.