Error starting spring boot - "An attempt was made to call a method that does not exist" - spring

I am trying to upgrade the Spring version for one of our projects.
The project structure is as listed below:
internalToolApp
internalToolAppServiceTier
The packages of the 2 sub-projects are listed below:
build.gradle of internalToolApp
buildscript {
ext {
springBootVersion = '2.6.9'
}
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'org.springframework.boot'
if (project.hasProperty("projVersion")) {
version = project.projVersion
} else {
version = "0.0-SNAPSHOT"
}
group = 'internalToolGroup'
// In this section you declare where to find the dependencies of your project
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
dependencies {
compile project(':internalToolAppServiceTier')
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
compile('com.github.ulisesbocchio:jasypt-spring-boot:2.1.0')
compile 'com.visa.commons.security.protectconfig:protectconfig-core:2.7.0'
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:3.1.4')
compile 'com.hazelcast:hazelcast-enterprise-all:4.2.1'
compile("com.hazelcast:hazelcast-spring:4.2.1")
compile("org.projectlombok:lombok:1.18.10")
compile('org.apache.tomcat:tomcat-jdbc:8.5.37')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0')
// Log4j 2
compile ('org.apache.logging.log4j:log4j-core:2.17.1')
compile ('org.apache.logging.log4j:log4j-api:2.17.1')
compile ('org.apache.logging.log4j:log4j-slf4j-impl:2.17.1')
compile ("commons-lang:commons-lang:2.6")
compile('org.apache.poi:poi:4.1.2')
compile('org.apache.poi:poi-ooxml:4.1.2')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
bootJar {
exclude ("application.properties")
exclude ("database.properties")
exclude ("filetransfer.properties")
exclude ("mongo_local_application.properties")
}
task setupProject {
doFirst {
File dir = new File("$buildDir/../../../coreconfig_commons")
if(!dir.exists()) {
def grgit = org.ajoberstar.grgit.Grgit.clone(dir: "$buildDir/../../../anotherInternalTool", uri: "https://.....git")
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
build.gradle of internalToolAppServiceTier
buildscript {
ext {
springBootVersion = '2.6.9'
}
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'maven'
apply plugin: 'maven-publish'
if (project.hasProperty("projVersion")) {
version = project.projVersion
} else {
version = "0.0-SNAPSHOT"
}
group = 'internalToolGroup'
// In this section you declare where to find the dependencies of your project
repositories {
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
maven {
url "https:..."
credentials {
username = "..."
password = "..."
}
}
}
configurations.all {
if (!project.hasProperty("local")) {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
if (project.hasProperty("local")) {
compile project(':CommonServiceTier')
compile project(':CommonUtility')
compile project(':CommonDBTier')
} else {
compile(group: 'internalToolGroup', name: 'CommonServiceTier', version: version){ changing = true }
compile(group: 'internalToolGroup', name: 'CommonUtility', version: version){ changing = true }
compile(group: 'internalToolGroup', name: 'CommonDBTier', version: version){ changing = true }
}
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
compile('org.springframework:spring-tx:5.0.12.RELEASE')
compile('com.github.ulisesbocchio:jasypt-spring-boot:2.1.0')
compile 'com.hazelcast:hazelcast-enterprise-all:4.2.1'
compile("com.hazelcast:hazelcast-spring:4.2.1")
compile("org.projectlombok:lombok:1.18.10")
compile("org.mongodb:mongo-java-driver:3.9.1")
compile('org.springframework.data:spring-data-mongodb:3.2.0')
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
compile('org.mybatis:mybatis:3.5.0')
compile('org.mybatis:mybatis-spring:2.0.0')
compile 'org.apache.velocity:velocity:1.7'
compile 'org.apache.velocity.tools:velocity-tools-generic:3.0'
compile('org.apache.poi:poi:4.1.2')
compile('org.apache.poi:poi-ooxml:4.1.2')
compile('com.ibm.db2:db2jcc_license_cisuz:1.0')
compile('com.ibm.db2:db2java:1.0')
compile('com.ibm.db2:jcc:11.5.0.0')
// Log4j 2
compile ('org.apache.logging.log4j:log4j-core:2.17.1')
compile ('org.apache.logging.log4j:log4j-api:2.17.1')
compile ('org.apache.logging.log4j:log4j-slf4j-impl:2.17.1')
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
configurations {
all*.exclude module : 'spring-boot-starter-logging'
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
When I run this project internalToolApp, i get some output, showing that the application is able to run, but after some time, the application fails & i get below error in the console:
[2023-01-26 16:59:55,238] [CompanyInternalTool] -- [...]- [main] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext [] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongo' threw exception; nested exception is java.lang.NoSuchMethodError: com.mongodb.MongoClientSettings$Builder.uuidRepresentation(Lorg/bson/UuidRepresentation;)Lcom/mongodb/MongoClientSettings$Builder;
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is SHUTTING_DOWN
Jan 26, 2023 4:59:55 PM com.hazelcast.client.impl.connection.ClientConnectionManager
INFO: hz.client_1 [dev] [4.2.1] Removed connection to endpoint: [10.93.88.241]:5701:2c82e08d-47f2-44ef-a24e-d539a81aac35, connection: ClientConnection{alive=false, connectionId=1, channel=NioChannel{/127.0.0.1:55728->localhost/127.0.0.1:5701}, remoteAddress=[10.93.88.241]:5701, lastReadTime=2023-01-26 16:59:54.312, lastWriteTime=2023-01-26 16:59:54.283, closedTime=2023-01-26 16:59:55.241, connected server version=4.2.1}
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is CLIENT_DISCONNECTED
Jan 26, 2023 4:59:55 PM com.hazelcast.core.LifecycleService
INFO: hz.client_1 [dev] [4.2.1] HazelcastClient 4.2.1 (20210630 - 6145014, 06a4018) is SHUTDOWN
Jan 26, 2023 4:59:55 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer.applyUuidRepresentation(MongoPropertiesClientSettingsBuilderCustomizer.java:67)
The following method did not exist:
com.mongodb.MongoClientSettings$Builder.uuidRepresentation(Lorg/bson/UuidRepresentation;)Lcom/mongodb/MongoClientSettings$Builder;
The calling method's class, org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer, is available from the following locations:
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.9/143e3b88bbf01a87d4877196c715e3b154d5e00c/spring-boot-autoconfigure-2.6.9.jar!/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.class
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.11/40e0e3011e8549b4591a0a3f26d21ba5978b6ed1/spring-boot-autoconfigure-2.6.11.jar!/org/springframework/boot/autoconfigure/mongo/MongoPropertiesClientSettingsBuilderCustomizer.class
The calling method's class was loaded from the following location:
file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/2.6.9/143e3b88bbf01a87d4877196c715e3b154d5e00c/spring-boot-autoconfigure-2.6.9.jar
The called method's class, com.mongodb.MongoClientSettings$Builder, is available from the following locations:
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.9.1/d313237180bf9f2f82e12f503d9617e6b070f792/mongo-java-driver-3.9.1.jar!/com/mongodb/MongoClientSettings$Builder.class
jar:file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongodb-driver-core/4.2.3/ac8159055a465139c643355aa3af7f4c050bceb2/mongodb-driver-core-4.2.3.jar!/com/mongodb/MongoClientSettings$Builder.class
The called method's class hierarchy was loaded from the following locations:
com.mongodb.MongoClientSettings.Builder: file:/C:/Users/hyusuf/.gradle/caches/modules-2/files-2.1/org.mongodb/mongo-java-driver/3.9.1/d313237180bf9f2f82e12f503d9617e6b070f792/mongo-java-driver-3.9.1.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer and com.mongodb.MongoClientSettings$Builder
I found a similar StackOverflow post [here](Error starting spring boot "An attempt was made to call a method that does not exist") that seems to indicate there is a duplicate package, I'm not quite sure how to detect that as I'm new to this.
Would anyone be able to provide a solution or guidance on what I should do?
Following #Pritam Sadhukhan's suggestion, i get the same error, althought slightly different, it mentions different versions of the same package causing issues
[2023-01-30 11:39:20,876] [CompanyInternalTool] -- [...]- [main] ERROR org.springframework.boot.SpringApplication [] - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$JdbcTransactionManagerConfiguration': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$JdbcTransactionManagerConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader#73d16e93]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955) ~[spring-beans-5.3.22.jar:5.3.22]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.21.jar:5.3.21]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.21.jar:5.3.21]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) [spring-boot-2.6.9.jar:2.6.9]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.6.9.jar:2.6.9]
at com.visa.coreconfig.pedit.CoreConfigPeditApp.main(CoreConfigPeditApp.java:154) [main/:?]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$JdbcTransactionManagerConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader#73d16e93]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.22.jar:5.3.22]
... 18 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/jdbc/support/JdbcTransactionManager
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_351]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_351]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_351]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.22.jar:5.3.22]
... 18 more
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.support.JdbcTransactionManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[?:1.8.0_351]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_351]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[?:1.8.0_351]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_351]
at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_351]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_351]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_351]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267) ~[spring-beans-5.3.22.jar:5.3.22]
... 18 more

Deinum,
Is this what the build.gradle should look like?
jackson
Replace
dependencies {
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
}
with
dependencies {
compile('org.springframework.data:spring-boot-starter-json')
}
mongo
Remove
compile("org.mongodb:mongo-java-driver:3.9.1")
compile('org.springframework.data:spring-data-mongodb:3.2.0')
with
compile('org.springframework.data:spring-data-mongodb:3.2.0')
spring-boot-starter-web
Replace
compile('org.springframework.boot:spring-boot-starter-web:2.6.9')
with
compile('org.springframework.boot:spring-boot-starter-web')
Is this all? or did i miss something

Can you please change the build.gradle of internalToolAppServiceTier and replace the following respectively?
compile('org.springframework:spring-tx:5.3.21')
Replace
compile('org.springframework.data:spring-data-mongodb:3.2.0')
to
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb:2.7.2'

Related

Error creating bean with name org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration (Using Gradle)

Building jar file works through the terminal computer path % ./gradlew build, and application runs computer path % java -jar name.jar.
Why not through IntelliJ?
*Secondary Issue -
When I try to upload the jar file built through the terminal to AWS Beanstalk I get a validation error.
*Primary Issue -
The application runs in IntelliJ.
After I have completed the Project Structure setup, and the Build Artifacts execution. The new .jar file fails to run,
throwing the exception below.
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
build.gradle:
plugins {
id 'org.springframework.boot' version '2.6.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'application'
}
group = 'com.example'
version = 'api'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
runtimeOnly 'mysql:mysql-connector-java'
}
test {
useJUnitPlatform()
}
mainClassName = 'com.example.name.applicationame'
task fatJar(type: Jar) {
bootJar {
launchScript()
}
manifest {
attributes 'Main-Class': "${mainClassName}"
duplicatesStrategy = 'include'
}
archiveBaseName = "name"
from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/name?useSSL=true
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
Thanks!

org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor encountered while upgrading Groovy and Spock

Using Gradle 7.1.1, Java 16, Groovy 3.0.8 and Spock 2.0-groovy-3.0
I'm getting this error when running ./gradlew clean test
Caused by: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:673)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1232)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1383)
at java.base/java.lang.Iterable.forEach(Iterable.java:74)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:95)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:97)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
... 25 more
Caused by: java.lang.NoClassDefFoundError: org/junit/platform/engine/support/discovery/SelectorResolver
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3305)
at java.base/java.lang.Class.getConstructor0(Class.java:3510)
at java.base/java.lang.Class.getConstructor(Class.java:2238)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:660)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:657)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:668)
... 36 more
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.discovery.SelectorResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 44 more
This is the build.gradle for the module where error is reported:
dependencies {
implementation 'io.rest-assured:rest-assured'
implementation 'org.yaml:snakeyaml'
implementation 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation('org.spockframework:spock-core') {
transitive = false
}
}
Parent module build.gradle file:
ext {
jupiterVersion = '5.7.2'
}
jar.enabled = false
subprojects {
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'codenarc'
jar.enabled = true
codenarc {
toolVersion = '1.4'
reportFormat = 'html'
configFile = new File('../../tool/codenarc/groovy-ruleset.groovy')
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.1") {
bomProperties(['selenium.version' : '3.141.59',
'rest-assured.version': '4.1.1'])
}
}
dependencies {
dependency 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
dependency 'org.spockframework:spock-core:2.0-groovy-3.0'
dependency 'com.athaydes:spock-reports:2.0-groovy-3.0'
dependency 'com.codeborne:selenide:5.3.1'
dependency 'org.hamcrest:hamcrest:2.1'
dependencySet(group: 'org.junit.jupiter', version: jupiterVersion) {
entry 'junit-jupiter'
entry 'junit-jupiter-api'
}
dependencySet(group: 'org.slf4j', version: '1.7.28') {
entry 'jcl-over-slf4j'
entry 'jul-to-slf4j'
}
dependencySet(group: 'org.aspectj', version: '1.9.4') {
entry 'aspectjrt'
entry 'aspectjweaver'
}
dependency 'io.rest-assured:rest-assured:4.1.1'
dependency 'org.postgresql:postgresql:42.2.8'
dependency 'org.yaml:snakeyaml:1.25'
dependency 'org.apache.poi:poi-ooxml:4.1.1'
dependency 'com.opencsv:opencsv:4.0'
dependency 'org.junit.platform:junit-platform-launcher:1.4.0'
}
}
test {
useJUnitPlatform()
}
}
Any help would be appreciated.
PS. This was working with Java 11, Groovy 2.5 and Spock 1.3-groovy-2.5
Have you added useJUnitPlatform()?
https://github.com/spockframework/spock-example/blob/master/build.gradle#L34
test {
useJUnitPlatform()
}
It was a problem with the parent project's build.gradle file.
I recently upgraded the spring boot version to 2.5.1.
After updating this entry in the build.gradle file the error went away.
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.1") {
bomProperties(['selenium.version' : '3.141.59',
'rest-assured.version': '4.1.1'])
}
}

Spring boot Eureka server project not starting

I just created Spring Boot project(with Gradle Buildship 3.x) and I enabled Eurekaserver on main class.I am getting following error
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'traceFilterRegistration' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'traceFilterRegistration' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.servlet.Filter' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Qualifier(value=httpTraceFilter)}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.2.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-web')
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-server', version: '2.0.1.RELEASE'
}
test {
useJUnitPlatform()
}
application.properties:
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
Issue that you encounter has been fix already, at May 13 2019, issue
spring-cloud-netflix
Though issue has been resolved over a year ago I encounter it lately. For reference, as workaround, you can add missing bean. It will be created only if not provided by spring cloud netfix:
#ConditionalOnMissingBean
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}

spring-boot-starter-jetty 1.4.x.RELEASE missing EmbeddedServletContainerFactory

When using the following gradle configuration:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-starter-app'
version = '0.1.0'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
compile.exclude module: "spring-boot-starter-logging"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE")
compile("org.springframework.boot:spring-boot-starter-actuator:1.4.1.RELEASE")
compile("org.springframework.boot:spring-boot-starter-jetty:1.4.1.RELEASE")
compile('org.springframework.boot:spring-boot-starter-log4j2:1.4.1.RELEASE')
testCompile("org.springframework.boot:spring-boot-starter-test:1.4.1.RELEASE")
testCompile("junit:junit")
}
```
The app won't start up, the exception being:
```
2016-11-07 09:36:22.900 ERROR 44150 --- [ main] o.s.b.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at com.mystuff.Application.main(Application.java:10) [main/:?]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:189) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
... 8 more
Note: I've also tried this with 1.4.0.
But when I backtrack to an 1.3.x.RELEASE it all works:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.8.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-starter-app'
version = '0.1.0'
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
compile.exclude module: "spring-boot-starter-logging"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.3.8.RELEASE")
compile("org.springframework.boot:spring-boot-starter-actuator:1.3.8.RELEASE")
compile("org.springframework.boot:spring-boot-starter-jetty:1.3.8.RELEASE")
compile('org.springframework.boot:spring-boot-starter-log4j2:1.3.8.RELEASE')
testCompile("org.springframework.boot:spring-boot-starter-test:1.3.8.RELEASE")
testCompile("junit:junit")
}
My application class looks like this:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
Googling around shows that the most common reasons for this are:
A missing spring-boot-starter-web dependency - not the case here
A missing maven plugin - not appropriate here
Why is this happening?
1.4.x uses Jetty 9.3 which requires java 8
I see in your build script that your are using Java 7. Spring Boot 1.4.x uses Jetty 9.3, which requires java 8 (see Spring Boot's Jetty vs Java versions)
Java 7 - Fallback to Jetty 9.2
If upgrading to Java 8 is not an option, you need to use Jetty 9.2 instead (see how-to-use-jetty-9.2-gradle). This can be done by redefining the property jetty.version:
ext['jetty.version'] = '9.2.17.v20160517'
dependencies {
compile ('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile ('org.springframework.boot:spring-boot-starter-jetty')
}

Spring Data Rest and spring-data-rest-hal-browser integration using Spring Boot

Problem
The Spring Data REST Reference Documentation says that
dependencies {
compile 'org.springframework.data:spring-data-rest-hal-browser'
}
is enough to integrate HAL browser with Spring Data Rest while using Spring Boot but Gradle complains this dependency cannot be found unless I specify particular version so I fixed it by specifying the latest one available in central repository (there is no other version available in the repository). After specifying the version the dependency is resolved but I get an error during Spring Boot container initialization:
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 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 151 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:966)
at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:95)
at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:88)
at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:81)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories(RepositoryRestMvcConfiguration.java:182)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.CGLIB$repositories$11(<generated>)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0$$FastClassBySpringCGLIB$$ec6a4119.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.repositories(<generated>)
at sun.reflect.NativeMetssorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 152 more
Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
... 173 more
However my application initializes successfully and works as expected if I remove spring-data-rest-hal-browser:2.4.0.RELEASE dependency.
Question
How can I setup my build.gradle correctly to have my application integrated with HAL browser properly?
build.gradle
buildscript {
ext {
springBootVersion = '1.2.7.RELEASE'
}
repositories {
mavenCentral()
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
[...]
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.data:spring-data-rest-hal-browser:2.4.0.RELEASE')
compile('org.projectlombok:lombok:1.16.6')
compile name: 'ojdbc6'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc:1.0.0.RELEASE')
}
The automatic version management for the HAL browser only works starting with Spring Boot 1.3.0 which is at the release candidate stage and should be released very soon. The release candidate is very stable for me, so you may consider giving that a try by updating your build to 1.3.0.RC1 which I would expect would fix the issue, something like this:
buildscript {
ext {
springBootVersion = '1.3.0.RC1'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone/' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
}
}
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.projectlombok:lombok:1.16.6')
compile name: 'ojdbc6'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}
You can see the managed dependency versions for 1.3.0.RC1 here:
http://docs.spring.io/spring-boot/docs/1.3.0.RC1/reference/htmlsingle/#appendix-dependency-versions
You'll notice if you look at the managed dependency versions for 1.2.7 that neither spring-data-rest-hal-browser nor spring-restdocs-mockmvc are present.
The package was renamed to spring-data-rest-hal-explorer. Here's an example of a modern configuration of HAL with Spring Boot 2 with automatic version management.
Maven example:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>
Gradle example:
plugins {
id "io.spring.dependency-management" version <<version>>
}
dependencies {
implementation('org.springframework.data:spring-data-rest-hal-explorer')
}

Resources