How does spring boot check for classes that don't exist on the classpath using conditionalonclass annotation? - spring

Somewhere it is mentioned that asm is used behind the scenes. If anyone can point me where it is done in the framework or an example would be greatly appreciated.

Imagine the following case
dependencyA contains dependencyB
and your POM looks like the following
<dependency>
<groupId>com.company.name</groupId>
<artifactId>dependencyA</artifactId>
<version>1.1.1</version>
<exclusions>
<exclusion>
<groupId>com.company.name</groupId>
<artifactId>dependencyB</artifactId>
</exclusion>
</exclusions>
</dependency>
so you added dependencyA excluding dependencyB to your project in the other word the dependencyB is not in your classPath --> so if you used #ConditionOnClass(com.company.name.dependencyB.myService.class) it wont execute the code

Related

Perfomance Test and API test are not working together in same framework

#ptrthomas - I am able to perform API test and performance test separate in karate. But when I try to merge both in same framework, either of them stopped working.
Reason that I can see here - karate-core is sub dependency of both karate-junit4 and karate-apache. But both of them install different version of karate-core. Hence either have to exclude one of them. But wherever you exclude it, it will stop working. If you exclude it from karate-junit4 then API test will not work, if you exclude it from karate-apache or gatling, performance will not work.
Is there any common version for dependencies for both performance and API test (which run through junit) or any github location where someone might have integrated both in one project?
Below are the version that I am using -
UTF-8 1.8 3.6.0 0.9.0.RC3 2.2.4
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.2.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>${karate.version}</version>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-gatling</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
Can someone please help here?
Just use this sample project: https://github.com/ptrthomas/karate-gatling-demo
This has the right dependencies set as a simple, stand-alone project and many teams have used and validated it.
If you are still facing issues, please follow the instructions here: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Ratpack 1.5.4 hystrix dependency cannot be resolved

I cannot compile my project that uses Ratpack 1.5.4 because there is a missing dependency to Hystrix 1.5.13 which cannot be resolved.
http://search.maven.org/#search%7Cga%7C1%7Cg%3A"com.netflix.hystrix"%20AND%20v%3A"1.5.13"
What is wrong here?
You can try excluding com.netflix:hystrix-core:1.5.13 from io.ratpack:ratpack-hystrix:1.5.4 and then you can add com.netflix:hystrix-core:1.5.12 directly to your pom.xml file, something like that:
<dependencies>
<dependency>
<groupId>io.ratpack</groupId>
<artifactId>ratpack-core</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>io.ratpack</groupId>
<artifactId>ratpack-hystrix</artifactId>
<version>1.5.4</version>
<exclusions>
<exclusion>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies>
I've tested this simple Maven Ratpack "Hello, World!" app https://github.com/wololock/ratpack-maven-example
It compiles in Travis without any issue - https://travis-ci.org/wololock/ratpack-maven-example (I have com.netflix:hystrix-core:1.5.13 in my local .m2 repository, so I wanted to use something with a clean local Maven repository like Travis CI)
I don't know if version 1.5.13 got rolled back or something like that. It can be found in MvnRepository.com https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core/1.5.13 however it says that 1.5.12 is newer, even though it got released 2 months earlier.

Maven artifact issue with stardog and sesame dependencies

I have a program, developed in a maven project through Eclipse, that provides an ETL service which ingests data, generates turtle format RDF using the Jena API, and loads it into a triple store which requires data sent to it using the Sesame API. As such, I need to convert the statements created by the ETL service from Jena to Sesame.
I want to use the following class from Stardog, as it does precisely what I need to do. I tried to add the following dependencies to my pom.xml to resolve the issue:
<dependency>
<groupId>com.complexible.stardog.protocols.http</groupId>
<artifactId>client</artifactId>
<version>${stardog.version}</version>
<exclusions>
<exclusion>
<!-- Depends on this as if it were a jar artifact, when it is a pom -->
<artifactId>sesame</artifactId>
<groupId>org.openrdf.sesame</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.complexible.stardog.reasoning.http</groupId>
<artifactId>client</artifactId>
<version>${stardog.version}</version>
<exclusions>
<exclusion>
<!-- Depends on this as if it were a jar artifact, when it is a pom -->
<artifactId>sesame</artifactId>
<groupId>org.openrdf.sesame</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.complexible.stardog</groupId>
<artifactId>core</artifactId>
<version>${stardog.version}</version>
<exclusions>
<exclusion>
<!-- Depends on this as if it were a jar artifact, when it is a pom -->
<artifactId>sesame</artifactId>
<groupId>org.openrdf.sesame</groupId>
</exclusion>
<exclusion>
<artifactId>license</artifactId>
<groupId>com.clarkparsia</groupId>
</exclusion>
<exclusion>
<artifactId>erg</artifactId>
<groupId>com.complexible.erg</groupId>
</exclusion>
</exclusions>
</dependency>
but I get the following errors:
Missing artifact com.complexible.stardog:shared:jar 2.2.2
Missing artifact org.openrdf.sesame:sesame:jar:2.7.12
Missing artifact com.complexible.stardog:api:jar.2.2.2
I also get errors on the opening Dependency tag for the above dependencies saying that the dependency contained within it is also missing.
Note: stardog.version = 2.2.2 and sesame.version = 2.7.12.
Any ideas?
I don't really know how to help you with the maven dependency problem - this looks very specific to Stardog. If you don't get an answer here you might try asking about this on their support mailinglist instead.
However, I can offer an alternative solution: instead of using a convertor class, you just serialize the Jena objects back to N-Triples or Turtle, and then parse them using Sesame's Rio parser - which will of course create Sesame API objects.
I'm not too familiar with the Jena API but I'm sure there is a way you can write a model to, say, an OutputStream in Turtle format. Once you have that OutputStream, you can simply do something like this:
// in case of very large files, use something more efficient, like a
// PipedOutputStream, or first write back to disk
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
// parse the data using Sesame Rio, which provides a Sesame Model
// object. You can of course also immediately write the
// data to the store instead of first creating a Model.
org.openrdf.model.Model model = Rio.parse(in, "", RDFFormat.TURTLE);

OpenJDK gives error: package org.jboss.weld.context.bound does not exist

I have a web app that compiles fine under Oracle's JDK 7, but gives the following error under OpenJDK 7:
error: package org.jboss.weld.context.bound does not exist
The error refers to a import in my code:
import org.jboss.weld.context.bound.BoundRequestContext;
In my pom.xml, I have the following weld-related dependencies:
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>1.1.8.Final</version>
<exclusions>
<exclusion>
<artifactId>jsr250-api</artifactId>
<groupId>javax.annotation</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-core</artifactId>
<version>1.1.8.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>1.1.8.Final</version>
</dependency>
Is there any way to make it compile using OpenJDK?
The problem is not OpenJDK's fault. You would most likely get the same problem with an Oracle badged JDK or a third-party Java compiler ... if you did an equivalent build with the respective compilers.
The problem is most likely caused by an incorrect Maven dependency.
According to GrepCode, that class (org.jboss.weld.context.bound.BoundRequestContext) is defined in "weld-api", "weld-servlet", "weld-se" and "weld-osgi-bundle". Try adding one of those as a dependency.
UPDATE
Judging from this page, "weld-api" is probably the way to go. You might want to read it thoroughly to figure out the recommended set of dependencies.

Does Spring Data force dependency on SLF4j?

The Spring docs explicitly mention that spring only depends on on commons-logging.
However, if i add a dependency to Spring Data MongoDb, gradle adds a dependency on slf4j.
org.springframework.data:spring-data-commons:1.5.1.RELEASE
+--- org.springframework:spring-core:3.1.4.RELEASE (*)
+--- org.springframework:spring-beans:3.1.4.RELEASE (*)
+--- org.slf4j:slf4j-api:1.7.1
\--- org.slf4j:jcl-over-slf4j:1.7.1
Does this mean I am forced to use SLF4j if i use spring data?
Yes, we have a compile time dependency on the Slf4j API as it's the de-facto standard logging API for Java and the one causing the least hassle of all the options available: JUL - I better don't leave a word on this one (see this one if you still need to be convinced), Commons Logging - runtime provider detection has proven a PITA.
We additionally require jcl-over-slf4j to provide a Commons Logging implementation to satisfy the Commons Logging dependency of the core Spring framework, a dependency it has to maintain for legacy reasons but would have not been introduced in the first place if Slf4j had been available back in the days.
So, yes. We're setting incentives to do the "right thing" (tm), read: "the way the Java community has agreed on at large". If you really want to stick to Commons Logging, simply add the slf4j-jcl bridge and you're set. If you want to remove the jcl-over-slf4j bridge, simply exclude the dependency.
You can disable SLF4J logging in Spring Data by adding to pom.xml:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
<!-- Exclude slf4j logging in favor of log4j -->
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
SLF4J is only a Logging Facade that in spring case will delegate in commons logging, using the jcl-over-slf4j dependency.
If you want your app to use commons-logging you can simply exclude slf4j dependencies.

Resources