I am getting this error when I try to run my Spring Boot app.
Exception starting filter [requestContextFilter]
java.lang.NoClassDefFoundError: jakarta/annotation/PostConstruct
This is my gradle file.
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id "com.google.protobuf" version "0.8.17"
}
group = 'Hospital'
version = '0.0.1-SNAPSHOT'
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.17.3"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.42.1'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'net.devh:grpc-server-spring-boot-starter:2.15.0.RELEASE'
implementation 'jakarta.annotation:jakarta.annotation-api:1.3.5'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
I am new to gRPC and java dependencies. What is the issue here? I added javax annotations to my dependencies but I still get previous error during runtime.
You're targeting the
1.3.5
version ofjakarta.annotation:jakarta.annotation-api
artifact.Like other artifact's after jakarta migration, eclipse team published older
javax
artifact's with the new coordinates.This
1.3.5
version isjavax
basedYou should use version starting from
2.0.0
,2.1.1
should be a good start.