-1

I am migrating my project to Spring Boot and am getting the following error in Test classes: java.jang.NoClassDefFoundError: javax/servlet/DispatcherType

my gradle:

plugins {
    id 'java'
    id 'jacoco'
    id 'org.sonarqube' version '4.0.0.2929'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'org.springframework.boot' version '3.0.5'
}

repositories {
     mavenCentral{
         url '********'
     }
 }

 group = '*****'
 sourceCompatibility = '17'

 apply from: 'gradle/sonar.gradle'

 dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
     implementation 'org.springframework.boot:spring-boot-starter-actuator'
     implementation 'org.springframework.boot:spring-boot-starter-security'

    // OAuth 2.0 Resource Server support
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'

    // Lombok
    implementation 'org.projectlombok:lombok:1.18.26'
    annotationProcessor 'org.projectlombok:lombok:1.18.26'`

    // Actuator
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    // Micrometer
    implementation 'io.micrometer:micrometer-registry-prometheus:1.10.6'
    // Logger
    implementation 'net.logstash.logback:logstash-logback-encoder:7.3'

    // Test
    testImplementation  'org`your text`.springframework.boot:spring-boot-starter-test'
    testImplementation 'com.github.tomakehurst:wiremock-jre8:2.35.0'
    testImplementation 'org.bitbucket.b_c:jose4j:0.7.6'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.26'
}


test {
   useJUnitPlatform()
   finalizedBy jacocoTestReport
}`
J Asgarov
  • 2,526
  • 1
  • 8
  • 18
  • Does this answer your question? [Why am I getting a NoClassDefFoundError in Java?](https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – Laurenz Albe Jul 11 '23 at 15:06

1 Answers1

0

Spring Boot 3+ is using Jakarta EE 9 as a base line, which means no more javax package. All the classes from namespace javax are migrated to jakarta namespace.

Check this link https://spring.io/blog/2022/11/24/spring-boot-3-0-goes-ga for Spring Boot, and this one for more info on migrating from javax to jakarta namespace https://www.youtube.com/watch?v=mukr2Q_zBm4

  • не помогло это. Всё сделано уже – Вадим Jul 07 '23 at 15:13
  • Then check if there are transient dependencies of `javax` jars. You can follow [gradle documentation](https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html) for viewing and debuging dependencies. – Veselin Perović Jul 08 '23 at 20:46