I am new to spring.
I was trying to upgrade spring boot version from 2.3.3.RELEASE to 2.6.7 in existing spring batch project.
Project build completed successfully but I am getting bellow error when I run batch. Please help.
Error
{
{"@timestamp":"2023-10-03T14:19:22.469+05:30","@version":"1","message":"Application run failed","logger_name":"org.springframework.boot.SpringApplication","thread_name":"restartedMain","level":"ERROR","level_value":40000,"stack_trace":"java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration.metricsRepositoryMethodInvocationListenerntat org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)ntat org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)ntat org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:193)ntat org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:153)ntat org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129)ntat org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343)ntat org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247)ntat org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311)ntat org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112)ntat org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:748)ntat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564)ntat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)ntat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)ntat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)ntat org.springframework.boot.SpringApplication.run(SpringApplication.java:307)ntat org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)ntat org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)ntat com.abc.edocagentui.Application.main(Application.java:12)ntat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)ntat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)ntat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)ntat java.base/java.lang.reflect.Method.invoke(Method.java:566)ntat org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)nCaused by: java.lang.IllegalStateException: @ConditionalOnMissingBean did not specify a bean using type, name or annotation and the attempt to deduce the bean’s type failedntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.validate(OnBeanCondition.java:490)ntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.(OnBeanCondition.java:439)ntat org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:155)ntat org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)nt… 22 common frames omittednCaused by: org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanTypeDeductionException: Failed to deduce bean type for org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration.metricsRepositoryMethodInvocationListenerntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:520)ntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanType(OnBeanCondition.java:509)ntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.(OnBeanCondition.java:432)nt… 24 common frames omittednCaused by: java.lang.NoClassDefFoundError: org/springframework/data/repository/core/support/RepositoryMethodInvocationListenerntat java.base/java.lang.ClassLoader.defineClass1(Native Method)ntat java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)ntat java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)ntat java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)ntat java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)ntat java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)ntat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)ntat java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)ntat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)ntat java.base/java.lang.Class.forName0(Native Method)ntat java.base/java.lang.Class.forName(Class.java:398)ntat org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:145)ntat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)ntat java.base/java.lang.Class.forName0(Native Method)ntat java.base/java.lang.Class.forName(Class.java:398)ntat org.springframework.boot.autoconfigure.condition.FilteringSpringBootCondition.resolve(FilteringSpringBootCondition.java:108)ntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.getReturnType(OnBeanCondition.java:528)ntat org.springframework.boot.autoconfigure.condition.OnBeanCondition$Spec.deducedBeanTypeForBeanMethod(OnBeanCondition.java:516)nt… 26 common frames omittednCaused by: java.lang.ClassNotFoundException: org.springframework.data.repository.core.support.RepositoryMethodInvocationListenerntat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)ntat java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)ntat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)nt… 44 common frames omittedn"}
{"@timestamp":"2023-10-03T14:19:22.471+05:30","@version":"1","message":"Unable to close ApplicationContext","logger_name":"org.springframework.boot.SpringApplication","thread_name":"restartedMain","level":"WARN","level_value":30000,"stack_trace":"java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.autoconfigure.metrics.data.RepositoryMetricsAutoConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@7c53a9eb]ntat org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)ntat org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:361)ntat org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:418)ntat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:765)ntat java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)ntat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:764)ntat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:703)ntat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:674)ntat org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1684)ntat org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)ntat org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)ntat org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:669)ntat org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:661)ntat org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1306)ntat org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:864)ntat org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:852)ntat org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:839)ntat org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:779)ntat org.springframework.boot.SpringApplication.run(SpringApplication.java:317)ntat org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)ntat org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)ntat com.abc.edocagentui.Application.main(Application.java:12)ntat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)ntat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)ntat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)ntat java.base/java.lang.reflect.Method.invoke(Method.java:566)ntat org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)nCaused by: java.lang.NoClassDefFoundError: org/springframework/data/repository/core/support/RepositoryMethodInvocationListenerntat java.base/java.lang.ClassLoader.defineClass1(Native Method)ntat java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)ntat java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)ntat java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)ntat java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)ntat java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)ntat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)ntat java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)ntat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)ntat java.base/java.lang.Class.getDeclaredMethods0(Native Method)ntat java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)ntat java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)ntat org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)nt… 26 common frames omittednCaused by: java.lang.ClassNotFoundException: org.springframework.data.repository.core.support.RepositoryMethodInvocationListenerntat java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)ntat java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)ntat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)nt… 39 common frames omittedn"}
}
my build.gradle
buildscript {
ext {
springBootVersion = "2.7.16"
awsSDKVersion = "1.12.300"
springCloudVersion = "2.2.5.RELEASE"
}
}
plugins {
id "org.springframework.boot" version "2.7.16"
id "com.abc.ccs.gradle.plugin.docker" version "2.0"
}
apply plugin: "java"
apply plugin: "idea"
apply plugin: "org.springframework.boot"
apply plugin: 'jacoco'
group "com.abc"
sourceCompatibility = 11
jacoco {
toolVersion = '0.8.5'
}
ccsDocker {
repositoryName = "microservices/edoc-agent-ui"
}
// Add integration test source sets
sourceSets {
integrationTest { sourceSet ->
["java", "groovy", "scala", "resources"].each {
if (!sourceSet.hasProperty(it)) return
sourceSet."$it".srcDir file("src/integrationTest/${it}")
}
}
}
configurations {
compile.exclude module: 'spring-boot-starter-tomcat'
}
dependencies {
implementation project(path: ":frontend", configuration: "output")
// Apache commons
implementation("org.apache.commons:commons-lang3:3.7")
// okhttpclient
implementation 'com.squareup.okhttp3:okhttp:3.12.3'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.3'
// Spring Boot
implementation("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-undertow:${springBootVersion}")
// javax annotations
implementation "org.hibernate.validator:hibernate-validator:6.0.20.Final"
// Sleuth, we need to list the dependencies manually as it uses BOM
implementation "org.springframework.cloud:spring-cloud-starter-sleuth:3.1.3"
//pdf fonts
implementation("com.abc:pdfutils-fonts:1.0.4")
// Metrics
implementation 'org.springframework.cloud:spring-cloud-aws-autoconfigure:2.2.6.RELEASE'
implementation 'io.micrometer:micrometer-registry-cloudwatch:1.10.2'
//CCS Metrics filtering
implementation('com.abc:ccs-spring-metrics:1.2')
// abc Security utils
implementation("com.abc:ccs-security:1.0.24")
// feign
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.8.7")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.8.7")
implementation("io.github.openfeign:feign-jackson:9.7.0")
implementation('io.github.openfeign:feign-okhttp:9.7.0')
implementation('io.github.openfeign:feign-slf4j:9.7.0')
implementation('io.github.openfeign.form:feign-form:3.3.0')
// swagger annotation, from java code copied from the edoc controller
implementation group: 'io.swagger', name: 'swagger-annotations', version: '1.5.0'
// spring sessions
implementation("org.springframework.session:spring-session-data-redis:2.3.0.RELEASE")
implementation("io.lettuce:lettuce-core:5.3.0.RELEASE")
// JWT
implementation("com.nimbusds:nimbus-jose-jwt:8.16")
// guava
implementation("com.google.guava:guava:25.1-jre")
// Apache libraries
implementation("commons-io:commons-io:2.6")
//logstash
implementation('net.logstash.logback:logstash-logback-encoder:7.2')
// aws
implementation("com.amazonaws:aws-java-sdk-s3:${awsSDKVersion}")
implementation("com.amazonaws:aws-java-sdk-ssm:${awsSDKVersion}"){
// https://github.com/spring-projects/spring-boot/issues/12816
exclude group: 'commons-logging', module: 'commons-logging'
}
testImplementation("org.springframework.boot:spring-boot-test:${springBootVersion}")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
testImplementation("org.mockito:mockito-core:4.8.0")
testImplementation "org.springframework.security:spring-security-test:5.3.2.RELEASE"
testImplementation(
'org.junit.jupiter:junit-jupiter-api:5.2.0'
)
testRuntimeOnly(
'org.junit.jupiter:junit-jupiter-engine:5.2.0',
'org.junit.vintage:junit-vintage-engine:5.2.0'
)
}
task junitIntegrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
test {
testLogging {
events "passed", "skipped", "failed"
}
reports {
junitXml.destination = new File("$rootProject.buildDir/test/results/xml")
junitXml.enabled = true
html.enabled = false
}
jacoco {
destinationFile = file("$rootProject.buildDir/test/coverage/work/${project.name}.exec")
}
useJUnitPlatform()
ignoreFailures = false
if (project.hasProperty("integration_tests")) {
include '**/integration/test/**'
} else if (project.hasProperty("performance_tests")) {
include '**/performance/test/**'
} else {
include '**/*TestSuite.*'
exclude '**/integration/test/**'
exclude '**/performance/test/**'
}
}
bootJar {
archiveFileName.set "application.jar"
mainClass = "com.abc.edocagentui.Application"
classifier "full"
manifest {
attributes "Bundle-Name": project.name
}
}
// 'dist' will basically compile and test
dist.dependsOn('build')
// 'integrationTest' will execute a Junit test that will run the integration tests
integrationTest.dependsOn('junitIntegrationTest')
2
Answers
I did not read your whole post but the exception stack trace says it:
You seem to miss that class. It seems to be part of spring data.
See: https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/core/support/RepositoryMethodInvocationListener.html since version 2.4.0
Add the dependency spring data commons and it should work. Something like:
Depending on your setup you might have to add a
<version>...</version>
tag if you don’t have the version defined somewhere in a parent…Or as you are using gradle something like (use the right version):
Judging from the amount of dependencies you are manually managing you have incompatible versions somewhere. Judging from the stacktrace it is due to the
spring-data-redis
dependency. You should be using thespring-boot-starter-data-redis
dependency to get the proper and compatible version.Further more I would suggest adding the
io.spring.dependency-management
plugin, which makes managing the versions a lot easier.spring-session-data-redis
spring-boot-starter-web
, you can addspring-boot-starter-json
if you want to be explicit.spring-boot-starter-validation
instead to get a proper and compatible version.spring-boot-starter-test
already includes, mockito, JUnit Jupiter and Spring BOot Test support.spring-security-test
dependency