Spring @ControllerAdvice - NoClassDefFoundError: javax/servlet/ServletException

Spring @ControllerAdvice - NoClassDefFoundError: javax/servlet/ServletException

我在 spring 项目中有我的 ExceptionHandler。我想在我的项目中使用@ControllerAdvice,但我遇到了一些麻烦。当我构建项目时,我有错误,但如果我评论@ControllerAdvice,我的项目构建 fine.For 构建我使用 gradle。下面我添加了错误代码,MyExceptionHandler 和 build.gradle.

java.lang.NoClassDefFoundError: javax/servlet/ServletException
    at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[na:na]
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600) ~[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:522) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[na:na]
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600) ~[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:522) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017) ~[na:na]
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642) ~[na:na]
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600) ~[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:522) ~[na:na]
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3215) ~[na:na]
    at java.base/java.lang.Class.getDeclaredConstructors(Class.java:2435) ~[na:na]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.findConstructorBindingAnnotatedConstructor(ConfigurationPropertiesBindConstructorProvider.java:62) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.getBindConstructor(ConfigurationPropertiesBindConstructorProvider.java:48) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forType(ConfigurationPropertiesBean.java:311) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:63) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
    at com.andreirozov.cyclingserver.CyclingserverApplication.main(CyclingserverApplication.java:10) ~[main/:na]
    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.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.2.6.RELEASE.jar:2.2.6.RELEASE]
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) ~[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:522) ~[na:na]
    ... 50 common frames omitted

我的异常处理程序:

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@ControllerAdvice
public class MyExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(EmptyListException.class)
    protected ResponseEntity<MyException> handleEmptyListException() {
        return new ResponseEntity<>(new MyException("Unexpected empty list"), HttpStatus.NOT_FOUND);
    }

    @ExceptionHandler(ParseException.class)
    protected ResponseEntity<MyException> handleParseException() {
        return new ResponseEntity<>(new MyException("Jsoup parse error"), HttpStatus.NOT_FOUND);
    }

    protected static class MyException {
        private String message;

        public MyException(String m) {
            message = m;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }
}

我的build.gradle:

plugins {
    id 'org.springframework.boot' version '2.2.6.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'war'
}

group = 'com.andreirozov'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.jsoup:jsoup:1.13.1'
    compile 'org.springframework.boot:spring-boot-starter-hateoas'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

依赖关系树:

compileClasspath - Compile classpath for source set 'main'.
+--- org.jsoup:jsoup:1.13.1
+--- org.springframework.boot:spring-boot-starter-hateoas -> 2.2.6.RELEASE
|    +--- org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE
|    |    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE
|    |    |    +--- org.springframework.boot:spring-boot:2.2.6.RELEASE
|    |    |    |    +--- org.springframework:spring-core:5.2.5.RELEASE
|    |    |    |    |    \--- org.springframework:spring-jcl:5.2.5.RELEASE
|    |    |    |    \--- org.springframework:spring-context:5.2.5.RELEASE
|    |    |    |         +--- org.springframework:spring-aop:5.2.5.RELEASE
|    |    |    |         |    +--- org.springframework:spring-beans:5.2.5.RELEASE
|    |    |    |         |    |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    |         |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    |         +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|    |    |    |         +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    |         \--- org.springframework:spring-expression:5.2.5.RELEASE
|    |    |    |              \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    +--- org.springframework.boot:spring-boot-autoconfigure:2.2.6.RELEASE
|    |    |    |    \--- org.springframework.boot:spring-boot:2.2.6.RELEASE (*)
|    |    |    +--- org.springframework.boot:spring-boot-starter-logging:2.2.6.RELEASE
|    |    |    |    +--- ch.qos.logback:logback-classic:1.2.3
|    |    |    |    |    +--- ch.qos.logback:logback-core:1.2.3
|    |    |    |    |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.12.1
|    |    |    |    |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.12.1
|    |    |    |    \--- org.slf4j:jul-to-slf4j:1.7.30
|    |    |    |         \--- org.slf4j:slf4j-api:1.7.30
|    |    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    +--- org.springframework.boot:spring-boot-starter-json:2.2.6.RELEASE
|    |    |    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE (*)
|    |    |    +--- org.springframework:spring-web:5.2.5.RELEASE
|    |    |    |    +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|    |    |    |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.3
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
|    |    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
|    |    |    \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.10.3
|    |    |         +--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |         \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
|    |    +--- org.springframework.boot:spring-boot-starter-tomcat:2.2.6.RELEASE
|    |    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    |    +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
|    |    |    +--- org.apache.tomcat.embed:tomcat-embed-el:9.0.33
|    |    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.33
|    |    |         \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
|    |    +--- org.springframework.boot:spring-boot-starter-validation:2.2.6.RELEASE
|    |    |    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE (*)
|    |    |    +--- jakarta.validation:jakarta.validation-api:2.0.2
|    |    |    \--- org.hibernate.validator:hibernate-validator:6.0.18.Final
|    |    |         +--- org.jboss.logging:jboss-logging:3.3.2.Final -> 3.4.1.Final
|    |    |         \--- com.fasterxml:classmate:1.3.4 -> 1.5.1
|    |    +--- org.springframework:spring-web:5.2.5.RELEASE (*)
|    |    \--- org.springframework:spring-webmvc:5.2.5.RELEASE
|    |         +--- org.springframework:spring-aop:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-context:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-expression:5.2.5.RELEASE (*)
|    |         \--- org.springframework:spring-web:5.2.5.RELEASE (*)
|    \--- org.springframework.hateoas:spring-hateoas:1.0.4.RELEASE
|         +--- org.springframework:spring-aop:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-context:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-web:5.2.5.RELEASE (*)
|         +--- org.springframework.plugin:spring-plugin-core:2.0.0.RELEASE
|         |    +--- org.springframework:spring-beans:5.2.0.RELEASE -> 5.2.5.RELEASE (*)
|         |    +--- org.springframework:spring-context:5.2.0.RELEASE -> 5.2.5.RELEASE (*)
|         |    +--- org.springframework:spring-aop:5.2.0.RELEASE -> 5.2.5.RELEASE (*)
|         |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|         +--- com.jayway.jsonpath:json-path:2.4.0
|         |    +--- net.minidev:json-smart:2.3
|         |    |    \--- net.minidev:accessors-smart:1.2
|         |    |         \--- org.ow2.asm:asm:5.0.4
|         |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|         \--- org.slf4j:slf4j-api:1.7.30
+--- org.springframework.boot:spring-boot-starter-web -> 2.2.6.RELEASE (*)
\--- javax.servlet:javax.servlet-api:3.1.0

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.jsoup:jsoup:1.13.1
+--- org.springframework.boot:spring-boot-starter-hateoas -> 2.2.6.RELEASE
|    +--- org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE
|    |    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE
|    |    |    +--- org.springframework.boot:spring-boot:2.2.6.RELEASE
|    |    |    |    +--- org.springframework:spring-core:5.2.5.RELEASE
|    |    |    |    |    \--- org.springframework:spring-jcl:5.2.5.RELEASE
|    |    |    |    \--- org.springframework:spring-context:5.2.5.RELEASE
|    |    |    |         +--- org.springframework:spring-aop:5.2.5.RELEASE
|    |    |    |         |    +--- org.springframework:spring-beans:5.2.5.RELEASE
|    |    |    |         |    |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    |         |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    |         +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|    |    |    |         +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    |         \--- org.springframework:spring-expression:5.2.5.RELEASE
|    |    |    |              \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    +--- org.springframework.boot:spring-boot-autoconfigure:2.2.6.RELEASE
|    |    |    |    \--- org.springframework.boot:spring-boot:2.2.6.RELEASE (*)
|    |    |    +--- org.springframework.boot:spring-boot-starter-logging:2.2.6.RELEASE
|    |    |    |    +--- ch.qos.logback:logback-classic:1.2.3
|    |    |    |    |    +--- ch.qos.logback:logback-core:1.2.3
|    |    |    |    |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    |    +--- org.apache.logging.log4j:log4j-to-slf4j:2.12.1
|    |    |    |    |    +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|    |    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.12.1
|    |    |    |    \--- org.slf4j:jul-to-slf4j:1.7.30
|    |    |    |         \--- org.slf4j:slf4j-api:1.7.30
|    |    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    |    +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    \--- org.yaml:snakeyaml:1.25
|    |    +--- org.springframework.boot:spring-boot-starter-json:2.2.6.RELEASE
|    |    |    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE (*)
|    |    |    +--- org.springframework:spring-web:5.2.5.RELEASE
|    |    |    |    +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|    |    |    |    \--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.3
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
|    |    |    +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.10.3
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
|    |    |    \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.10.3
|    |    |         +--- com.fasterxml.jackson.core:jackson-core:2.10.3
|    |    |         \--- com.fasterxml.jackson.core:jackson-databind:2.10.3 (*)
|    |    +--- org.springframework.boot:spring-boot-starter-tomcat:2.2.6.RELEASE
|    |    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    |    +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
|    |    |    +--- org.apache.tomcat.embed:tomcat-embed-el:9.0.33
|    |    |    \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.33
|    |    |         \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
|    |    +--- org.springframework.boot:spring-boot-starter-validation:2.2.6.RELEASE
|    |    |    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE (*)
|    |    |    +--- jakarta.validation:jakarta.validation-api:2.0.2
|    |    |    \--- org.hibernate.validator:hibernate-validator:6.0.18.Final
|    |    |         +--- org.jboss.logging:jboss-logging:3.3.2.Final -> 3.4.1.Final
|    |    |         \--- com.fasterxml:classmate:1.3.4 -> 1.5.1
|    |    +--- org.springframework:spring-web:5.2.5.RELEASE (*)
|    |    \--- org.springframework:spring-webmvc:5.2.5.RELEASE
|    |         +--- org.springframework:spring-aop:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-context:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|    |         +--- org.springframework:spring-expression:5.2.5.RELEASE (*)
|    |         \--- org.springframework:spring-web:5.2.5.RELEASE (*)
|    \--- org.springframework.hateoas:spring-hateoas:1.0.4.RELEASE
|         +--- org.springframework:spring-aop:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-beans:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-context:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-core:5.2.5.RELEASE (*)
|         +--- org.springframework:spring-web:5.2.5.RELEASE (*)
|         +--- org.springframework.plugin:spring-plugin-core:2.0.0.RELEASE
|         |    +--- org.springframework:spring-beans:5.2.0.RELEASE -> 5.2.5.RELEASE (*)
|         |    +--- org.springframework:spring-context:5.2.0.RELEASE -> 5.2.5.RELEASE (*)
|         |    +--- org.springframework:spring-aop:5.2.0.RELEASE -> 5.2.5.RELEASE (*)
|         |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|         +--- com.jayway.jsonpath:json-path:2.4.0
|         |    +--- net.minidev:json-smart:2.3
|         |    |    \--- net.minidev:accessors-smart:1.2
|         |    |         \--- org.ow2.asm:asm:5.0.4
|         |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
|         \--- org.slf4j:slf4j-api:1.7.30
+--- org.springframework.boot:spring-boot-devtools -> 2.2.6.RELEASE
|    +--- org.springframework.boot:spring-boot:2.2.6.RELEASE (*)
|    \--- org.springframework.boot:spring-boot-autoconfigure:2.2.6.RELEASE (*)
+--- org.springframework.boot:spring-boot-starter-web -> 2.2.6.RELEASE (*)
+--- javax.servlet:javax.servlet-api:3.1.0
\--- org.springframework.boot:spring-boot-starter-tomcat -> 2.2.6.RELEASE (*)

providedRuntime - Additional runtime classpath for libraries that should not be part of the WAR archive.
+--- javax.servlet:javax.servlet-api:3.1.0
\--- org.springframework.boot:spring-boot-starter-tomcat -> 2.2.6.RELEASE
     +--- jakarta.annotation:jakarta.annotation-api:1.3.5
     +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33
     +--- org.apache.tomcat.embed:tomcat-embed-el:9.0.33
     \--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.33
          \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.33

它不需要独立的 jar 应用程序:providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'。 Starter-web 包括一个

当您声明此依赖项时,您说您构建以排除 tomcat 独立 运行。这意味着 - 里面没有 servlet 库


如果您在某处部署此应用程序,则只需从 starter-web 中排除 tomcat,如下所示:

compile('org.springframework.boot:spring-boot-starter-web'){
    exclude module: "spring-boot-starter-tomcat"
}