ClassNotFoundException exception when using library - java

I created a common library to use it in my spring microservices.
In this library I used some other libraries (example: libphonenumber).
I created the jar file and imported it into another project, and I used it without any problem.
But when building the project, this exception is thrown :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'phoneUtils': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.weryou.backend.commons.utils.PhoneUtils] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#368239c8]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:265) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1269) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1184) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
at com.weryou.backend.mission.MissionAppKt.main(MissionApp.kt:13) ~[main/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.weryou.backend.commons.utils.PhoneUtils] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#368239c8]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:507) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:404) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:389) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:248) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 18 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/google/i18n/phonenumbers/Phonenumber$PhoneNumber
at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167) ~[na:na]
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2310) ~[na:na]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:489) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.google.i18n.phonenumbers.Phonenumber$PhoneNumber
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
... 25 common frames omitted
I do not know why this exception is thrown from the project where I imported the library .. normally if there is a problem at the dependencies of the library, the library does not work, but it works.
But when i put in the project gradle the same dependencies used in the library, everything works fine.
normally if I used dependencies in a library, I do not need to implement them in the project that the library uses.
I tried to make the dependencies of the library transitive, but that does not works!
this is the gradle file of the library :
plugins {
kotlin("jvm") version "1.3.50"
}
group = "com.weryou.backend"
version = "1.0.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation("io.jsonwebtoken:jjwt:0.9.1") {
isTransitive = true
}
implementation("com.googlecode.libphonenumber:libphonenumber:8.10.14") {
isTransitive = true
}
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.9") {
isTransitive = true
}
}
and this is the gradle file of the project that use the library
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.7.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
group = "com.project.test"
version = "0.0.1"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.boot:spring-boot-starter-web")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR2")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}

If you look at your consuming project, you declare a dependency to your common library like this
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
// ...
}
A jar file in itself does not contain any information on all the transitive dependencies it needs*. So there is no way that your consuming project would know that just by looking at the jar file.
There are several ways you can do this, and it all depends on your layout and how tightly coupled you like the projects to be. Here are a few of them:
In the consuming project, declare all required dependencies for the library (again). This is what you have already tried and said works fine. Hopefully now you know why. The downside is that you will have to keep them synchronized manually.
Create a Maven distribution of your library and have your consuming project depend on it like you do for all the other dependencies. This requires you to have a Maven repository to be able to upload it to. In this approach, the transitive dependencies will
be registered in the corresponding POM file.
If the projects are in on the same machine, you can import the library as a composite build, and declare it as a project dependency. In this approach, Gradle will infer the transitive dependencies from the Gradle project itself.
(*) Unless you are using a manifest file or building it as a "fat" jar, which I assume you don't and won't recommend anyway.

Related

Optaplanner - spring BeanCreationException

I'm migrating Optaplanner from v7.x to v8.14 on a project that uses spring-boot (as a web api).
I've added the optaplanner-spring-boot-starter dependency to the project, however when starting the application, I got the following error :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solverManager' defined in class path resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at be.my.WebgardesApplication.main(WebgardesApplication.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
... 24 common frames omitted
Caused by: java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.processSolutionAnnotations(SolutionDescriptor.java:269)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.processAnnotations(SolutionDescriptor.java:212)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.buildSolutionDescriptor(SolutionDescriptor.java:120)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildSolutionDescriptor(DefaultSolverFactory.java:160)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildScoreDirectorFactory(DefaultSolverFactory.java:133)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildSolver(DefaultSolverFactory.java:87)
at org.optaplanner.core.impl.solver.DefaultSolverManager.validateSolverFactory(DefaultSolverManager.java:69)
at org.optaplanner.core.impl.solver.DefaultSolverManager.<init>(DefaultSolverManager.java:58)
at org.optaplanner.core.api.solver.SolverManager.create(SolverManager.java:111)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration.solverManager(OptaPlannerAutoConfiguration.java:98)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration$$EnhancerBySpringCGLIB$$8803e22a.CGLIB$solverManager$2(<generated>)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration$$EnhancerBySpringCGLIB$$8803e22a$$FastClassBySpringCGLIB$$40c364cf.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
at org.optaplanner.spring.boot.autoconfigure.OptaPlannerAutoConfiguration$$EnhancerBySpringCGLIB$$8803e22a.solverManager(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 25 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
Caused by: java.lang.IllegalStateException: The solutionClass (class be.my.domain.MySolution) has been specified as a solution in the configuration, but does not have a #PlanningSolution annotation.
The project is in two separated modules, one with everything related to Optaplanner (the config.xml, the .drl, the Solution, etc), the other is the spring-boot web api.
Here are the dependencies (.gradle) for both :
module "my-roster"
dependencies {
implementation 'org.springframework:spring-web:5.1.6.RELEASE'
implementation 'org.springframework:spring-context:5.0.10.RELEASE'
implementation 'org.springframework.boot:spring-boot:2.1.4.RELEASE'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:27.0.1-jre'
implementation "org.mapstruct:mapstruct:1.3.0.Final"
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final"
implementation "org.optaplanner:optaplanner-core:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-persistence-xstream:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-spring-boot-starter:${optaplannerVersion}"
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.11.0'
implementation "org.zalando:problem-spring-web:0.24.0-RC.0"
implementation "net.logstash.logback:logstash-logback-encoder:5.2"
runtimeOnly 'org.springframework.boot:spring-boot-devtools:2.1.4.RELEASE'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
testAnnotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final"
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5.12'
implementation 'org.json:org.json:chargebee-1.0'
implementation 'org.apache.commons:commons-lang3:3.0'
}
module "web-app"
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final"
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner'
implementation "org.zalando:problem-spring-web:0.24.0-RC.0"
implementation "net.logstash.logback:logstash-logback-encoder:5.2"
implementation "org.optaplanner:optaplanner-core:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-persistence-xstream:${optaplannerVersion}"
implementation "org.optaplanner:optaplanner-spring-boot-starter:${optaplannerVersion}"
implementation project(':my-roster')
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.7'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.7'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5.12'
implementation 'org.json:org.json:chargebee-1.0'
}
the SolverConfig file :
<solver xmlns="https://www.optaplanner.org/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.optaplanner.org/xsd/solver https://www.optaplanner.org/xsd/solver/solver.xsd">
<solutionClass>be.my.domain.MySolution</solutionClass>
<entityClass>be.my.domain.DutyAssignment</entityClass>
...
</solver>
And the MySolution file :
package be.my.domain;
// Imports ...
#PlanningSolution
#XStreamAlias("MySolution")
public class MySolution extends AbstractPersistable {
private static final long serialVersionUID = 1L;
private String code;
//All the #ProblemFactProperty / CollectionProperty and the ProblemEntityCollectionProperty
#PlanningScore
private HardMediumSoftScore score;
public MySolution(){}
//A lot of getters
}
EDIT : The #PlanningSolution class and the configuration files are in one module, the solverConfig, solverFactory, scoreManager, etc. are all built in the other package, could this be an issue in v8+ ?
This is a bug in Optaplanner, the current workaround is to move the needed code from the different modules into one. Not ideal, but it works. To follow the issue : https://issues.redhat.com/browse/PLANNER-2600 Once resolved, this bug should not happen anymore.

Gradle not including one dependency when creating the artifact

I am using Gradle in an IntelliJ project to manage dependencies in a Spring project to provide REST web services. As long as I run the project in the IDE it works fine, but if I execute the java -jar artifact.jar command it cannot start. The following error is printed
13:42:47.338 [main] WARN org.springframework.boot.SpringApplication - Unable to close ApplicationContext
java.lang.IllegalStateException: Failed to introspect Class [com.(...).web_services.JmsConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader#2cdf8d8a]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:747)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:746)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:685)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:656)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:667)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:659)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1300)
at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:914)
at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:902)
at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:889)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:830)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:349)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
at com.(...).web_services.WebServicesApplication.main(WebServicesApplication.java:10)
Caused by: java.lang.NoClassDefFoundError: javax/jms/ConnectionFactory
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.jms.ConnectionFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 25 common frames omitted
I suppose the javax.jms.ConnectionFactory class comes with the Spring ActiveMQ package, and I already tried to update Gradle manually but that did not solve the problem. Also importing javax.jms.ConnectionFactory in the JMS class did not help. Any clue?
The first attempt was to create a fat jar using the following custom gradle task (as suggested by #MatteoNNZ following this guide).
task customFatJar(type: Jar) {
manifest {
attributes 'Main-Class': '<myPackage>.<myMainClass>'
}
baseName = 'all-in-one-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
However, as this didn't work, I ran the predefined gradle task buildDependents that created a working .jar in the build/libs folder.

Spring kafka error Caused by: java.lang.ClassNotFoundException: org.springframework.kafka.transaction.KafkaAwareTransactionManager

This is wired just started spring boot project with simple main class, it works fine without spring-kafka dependency but after adding spring-kafka and spring-kafka-test blows up with exception, github here
gradle.build
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.0.RELEASE'
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.0.5.RELEASE'
testCompile group: 'org.springframework.kafka', name: 'spring-kafka-test', version: '2.0.5.RELEASE'
}
Main class
#SpringBootApplication
public class KafkaMain {
public static void main(String[] args) {
SpringApplication.run(KafkaMain.class, args);
}
}
Error
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-12-16 19:32:29.347 ERROR 39854 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Erro creating beanwithname'org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration': Unexpected exception during bean creation; nested exception is java.lang.TypeNotPresentException: Type org.springframework.kafka.transaction.KafkaAwareTransactionManager not present
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:511) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.kafka.KafkaMain.main(KafkaMain.java:10) [bin/:na]
Caused by: java.lang.TypeNotPresentException: Type org.springframework.kafka.transaction.KafkaAwareTransactionManager not present
Spring for Apache Kafka 2.0.x is not compatible with Spring Boot 2.1.x. You have to use Spring-Kafka 2.2.x. More over would be better to just rely on the dependency from Spring Boot per se. please, see https://start.spring.io/ for more info how properly start the project for Spring Boot.
And please, don’t duplicate your question in different places if that was not asked.

Spring-Data Neo4J #Repository #Query not working

The following is the stacktrace generated after the exception is thrown:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-18 10:45:31.825 ERROR 16349 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositoryPropertyReferenceController' defined in URL [jar:file:/home/sean/.gradle/caches/modules-2/files-2.1/org.springframework.data/spring-data-rest-webmvc/3.1.0.RC2/11b3ab6953b3a0f6a433e48be1b0d2db668602c5/spring-data-rest-webmvc-3.1.0.RC2.jar!/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositories' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'matchRepo': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:766) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:217) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1302) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:829) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:865) ~[spring-context-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548) ~[spring-context-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.M3.jar:2.1.0.M3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:797) [spring-boot-2.1.0.M3.jar:2.1.0.M3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:421) [spring-boot-2.1.0.M3.jar:2.1.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:340) [spring-boot-2.1.0.M3.jar:2.1.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) [spring-boot-2.1.0.M3.jar:2.1.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1279) [spring-boot-2.1.0.M3.jar:2.1.0.M3]
at io.sciro.leaderdata.LeaderDataApp.main(LeaderDataApp.java:22) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositories' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'matchRepo': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:624) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:455) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1282) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1126) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:290) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1222) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1149) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:854) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:757) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'matchRepo': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:619) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
... 33 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'matchRepo': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1743) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1091) ~[spring-context-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:97) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:90) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:83) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories(RepositoryRestMvcConfiguration.java:242) ~[spring-data-rest-webmvc-3.1.0.RC2.jar:3.1.0.RC2]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$bb148bd0.CGLIB$repositories$5(<generated>) ~[spring-data-rest-webmvc-3.1.0.RC2.jar:3.1.0.RC2]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$bb148bd0$$FastClassBySpringCGLIB$$e615e97.invoke(<generated>) ~[spring-data-rest-webmvc-3.1.0.RC2.jar:3.1.0.RC2]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$bb148bd0.repositories(<generated>) ~[spring-data-rest-webmvc-3.1.0.RC2.jar:3.1.0.RC2]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
... 34 common frames omitted
Caused by: java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:545) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.1.0.RC2.jar:2.1.0.RC2]
at org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactoryBean.afterPropertiesSet(Neo4jRepositoryFactoryBean.java:66) ~[spring-data-neo4j-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1802) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1739) ~[spring-beans-5.1.0.RC3.jar:5.1.0.RC3]
... 55 common frames omitted
Process finished with exit code 1
My repository is written as follows:
package io.sciro.leaderdata.repo;
import io.sciro.leaderdata.domain.Match;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;
#Repository
#RepositoryRestResource(path = "match", collectionResourceRel = "match")
public interface MatchRepo extends Neo4jRepository<Match, Long> {
//If I delete the line below, everything works fine.
Match findMatchByCodeName(String codeName);
//If I delete the line below, everything works fine.
Iterable<Match> findMatchesByCodeName(#Param("codeName") String codeName);
}
My entity/domain:
#NodeEntity
public class Match {
#Id
#GeneratedValue
private Long id;
private String codeName;
private Long round;
private String me;
private String pc;
private Character result;
private Date timestamp;
#LastModifiedDate
private Date lastUpdated;
#CreatedDate
private Date created;
//Getters & Setters
}
I have the following Gradle Script:
buildscript {
ext {
springBootVersion = '2.1.0.M3'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.sciro'
version = '0.1'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
ext {
springBootAdminVersion = '2.1.0-SNAPSHOT'
springCloudVersion = 'Greenwich.BUILD-SNAPSHOT'
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-neo4j')
compile('org.springframework.data:spring-data-neo4j:5.0.9.RELEASE')
compile('org.neo4j:neo4j-ogm-bolt-driver:3.1.1-RC1')
compile('org.neo4j:neo4j-ogm-http-driver:3.1.1-RC1')
compile('org.springframework.boot:spring-boot-autoconfigure')
compile('org.springframework.boot:spring-boot-starter-data-rest')
// compile('org.springframework.boot:spring-boot-starter-hateoas')
compile('de.codecentric:spring-boot-admin-starter-client')
compile('de.codecentric:spring-boot-admin-starter-server')
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
// https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core
// compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
// compile('org.springframework.cloud:spring-cloud-starter-netflix-hystrix-dashboard')
// compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.springframework.cloud:spring-cloud-config-client')
// runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-parent
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-parent', version: 'Finchley.RELEASE', ext: 'pom'
}
dependencyManagement {
imports {
mavenBom "de.codecentric:spring-boot-admin-dependencies:${springBootAdminVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
Am I missing something? I'm kinda stuck on this issue now. An alternative solution that worked for me, was to delete these two lines of code from the MatchRepo interface:
//If I delete the line below, everything works fine.
Match findMatchByCodeName(String codeName);
//If I delete the line below, everything works fine.
Iterable<Match> findMatchesByCodeName(#Param("codeName") String codeName);
I just use findAll() method extended from the extended Neo4jRepository interface & then use java-8 stream to filter for the Match object that matches the codeName. An ugly solution indeed. If anyone knows how to fix this issue the right way, please help.
Edit: it seems that you're using incompatible versions of Spring-Data-Commons and Spring Data Neo4j. You're overwriting the version of SDN to 5.0.9 but not the Release Train Version.
Anyway, recommended naming scheme is something like this for derived method names:
package io.sciro.leaderdata.repo;
import io.sciro.leaderdata.domain.Match;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;
#Repository
#RepositoryRestResource(path = "match", collectionResourceRel = "match")
public interface MatchRepo extends Neo4jRepository<Match, Long> {
Match findOneByCodeName(String codeName);
Iterable<Match> findAllByCodeName(#Param("codeName") String codeName);
}

java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties

#Configuration
#EnableTransactionManagement
public class DataSourceConfig {
#Bean(destroyMethod = "shutdown")
public DataSource dataSource(){
EmbeddedDatabaseBuilder databaseBuilder = new EmbeddedDatabaseBuilder();
databaseBuilder.setType(EmbeddedDatabaseType.H2);
databaseBuilder.addScript("classpath:db/migration/V1__Create_Books_Table.sql");
databaseBuilder.addScript("classpath:db/migration/V2__Add_Books.sql");
return databaseBuilder.build();
}
#Bean
public JpaVendorAdapter vendorAdapter(){
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setDatabase(Database.H2);
vendorAdapter.setShowSql(true);
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect");
return vendorAdapter;
}
#Bean(name = "entityManagerFactory")
public EntityManagerFactory managerFactory(){
Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop");
LocalContainerEntityManagerFactoryBean managerFactoryBean = new LocalContainerEntityManagerFactoryBean();
managerFactoryBean.setDataSource(dataSource());
managerFactoryBean.setJpaVendorAdapter(vendorAdapter());
managerFactoryBean.setPackagesToScan("com.sammy");
managerFactoryBean.setJpaProperties(jpaProperties);
managerFactoryBean.afterPropertiesSet();
return managerFactoryBean.getObject();
}
#Bean
public PlatformTransactionManager transactionManager(){
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(managerFactory());
return transactionManager;
}
}
That is my configuration class and my gradle build file is
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarVersion}"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.sonarqube'
apply plugin: 'org.springframework.boot'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
jar{
group 'com.sammy'
version '1.0-SNAPSHOT'
}
dependencies {
testCompile "junit:junit:${junitVersion}"
testCompile "info.cukes:cucumber-java:${cucumberVersion}"
testCompile "info.cukes:cucumber-junit:${cucumberVersion}"
//testCompile "info.cukes:cucumber-spring:${cucumberVersion}"
testCompile 'org.springframework.boot:spring-boot-starter-test'
compile 'com.h2database:h2'
compile "org.flywaydb:flyway-core:${flywayVersion}"
compile "org.projectlombok:lombok:${lombokVersion}"
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile "org.hibernate:hibernate-core:${hibernateVersion}"
compile 'org.springframework.boot:spring-boot-starter-aop'
compile 'org.springframework.boot:spring-boot-starter-jetty'
compile "io.springfox:springfox-swagger2:${swaggerVersion}"
compile "org.jadira.usertype:usertype.core:${jadiraVersion}"
compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.cloud:spring-cloud-starter-config'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
//compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
task wrapper(type :Wrapper){
gradleVersion = '3.4.1'
}
While my gradle properties file is
junitVersion = 4.12
sonarVersion = 2.2.1
flywayVersion = 4.1.2
swaggerVersion = 2.6.1
cucumberVersion = 1.2.5
lombokVersion = 1.16.14
jadiraVersion = 6.0.1.GA
hibernateVersion = 5.2.9.Final
springBootVersion = 1.5.2.RELEASE
This issue is, I want to use Java 8's LocalDate in my entity class but, this still doesn't work without throwing this error message:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/sammy/config/DataSourceConfig.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at com.sammy.SpringDataTutorials.main(SpringDataTutorials.java:18) [main/:na]
Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties;
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:124) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:890) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 16 common frames omitted
Whether I add jadira core or spi library to my gradle build file, I still get the same error. SpringBoot uses spring-orm-4.3.7.RELEASE as is in the stacktrace then adding hibernate core version 5.2.9.FINAL upgrades it to that version. I've looked at almost all the different issues mentioned here but none deals with this version. I've also read through the hibernate current version document which says it should just work but it isn't for me so not sure why.
INFO 26648 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found. I changed the JpaTransactionManager to use the injected entityManagerFactory as one of those answers suggested but it still didn't work even after rebuilding the project with gradle and intellij. I looked at the Hibernate 5.2.9.FINAL docs and that method getProperties() no longer exists but inherited from entitiyManagerFactory. Also, most of the answers were done in xml config not the Java one as I've got up there and none of the answers described how to change it into a map in a java config situation rather than using the properties. When I drop hibiernates version to 5.1.x, that error message goes but the error message for the Java 8 LocalDate type is displayed which I found is because there's no support for Java's feature in that version of hibernate.
If you're getting this error when upgrading from gradle 3.x to 4.x, it has something to do with the way transitive Hibernate dependencies are resolved. I found that hibernate-entitymanager is now included in my dependencies.
Run gradle dependencyInsight --dependency hibernate to see your hibernate dependencies. If you have the now-deprecated hibernate-entitymanager in your project, exclude it.
In gradle 4.x, this can be done like
configurations.all {
exclude(group: 'org.hibernate', module: 'hibernate-entitymanager')
}
What version of the Gradle do you have?
I ask, because I have the same error which occurs after upgrade Gradle from 3.5 to 4.3. The same Hibernate version (5.2.9), the same Spring Boot (1.5.8) but in Gradle 3.5. - OK, 4.3 fail.
I've tested and latest version working fine was for me 3.5.1. I've tested versions from 4.0 to 4.4-rc-6 (latest at this moment).
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip
Based on the link given by Neil, I was able to find a way to create and use the setJpaPropertyMap() to set the properties Map. Then it gave me a different error with LoadTimeWeaverswhich I used
#Bean
public InstrumentationLoadTimeWeaver loadTimeWeaver() throws Exception {
InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
return loadTimeWeaver;
}
to solve. This then gave me the error message of
java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
for which I used this link http://gradle.1045684.n5.nabble.com/Java-Agent-LTW-problem-with-Gradle-and-Jetty-td4938600.html since it's a gradle project to solve and just changed the version to the current Spring instrumentation version. I believe you'll see this isn't a duplication hopefully with all the required steps to solve this issue.

Categories