当前位置: 首页 > 面试题库 >

从Gradle中的Spring Boot中排除Tomcat依赖项

蒋何平
2023-03-14
问题内容

我正在将Spring Boot与Jetty一起使用,看来我不能在Gradle构建文件中排除所有Tomcat依赖项。

build.gradle的相关部分:

compile("org.springframework.boot:spring-boot-starter") {
    exclude module: "tomcat-embed-el"
}
compile("org.springframework.boot:spring-boot-starter-jetty")

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

但是,当我运行gradle dependencies部分tomcat时,仍然存在,并导致WebSockets出现问题:

...
|    
+--- org.springframework.boot:spring-boot-starter-web: -> 1.4.1.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.4.1.RELEASE (*)
|    +--- org.hibernate:hibernate-validator:5.2.4.Final
|    |    +--- javax.validation:validation-api:1.1.0.Final
|    |    +--- org.jboss.logging:jboss-logging:3.2.1.Final -> 3.3.0.Final
|    |    \--- com.fasterxml:classmate:1.1.0 -> 1.3.1
|    +--- com.fasterxml.jackson.core:jackson-databind:2.8.3
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0 -> 2.8.3
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.8.3
|    +--- org.springframework:spring-web:4.3.3.RELEASE
|    |    +--- org.springframework:spring-aop:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.3.3.RELEASE (*)
|    |    \--- org.springframework:spring-core:4.3.3.RELEASE
|    +--- org.springframework:spring-webmvc:4.3.3.RELEASE
|    |    +--- org.springframework:spring-aop:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.3.3.RELEASE (*)
|    |    +--- org.springframework:spring-core:4.3.3.RELEASE
|    |    +--- org.springframework:spring-expression:4.3.3.RELEASE (*)
|    |    \--- org.springframework:spring-web:4.3.3.RELEASE (*)
|    \--- org.springframework.boot:spring-boot-starter-tomcat:1.4.1.RELEASE
|         +--- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
|         +--- org.apache.tomcat.embed:tomcat-embed-el:8.5.5
|         \--- org.apache.tomcat.embed:tomcat-embed-websocket:8.5.5
|              \--- org.apache.tomcat.embed:tomcat-embed-core:8.5.5
...

为什么不spring-boot-starter-tomcat排除在外spring-boot-starter-web


问题答案:

啊哈,找到原因了。

我也有compile("org.springframework.boot:spring-boot-starter- websocket")依赖,也依赖spring-boot-starter-tomcat。Gradle依赖项输出使我误认为这spring-boot- starter-web是Tomcat仍然存在的原因。

我必须添加以下内容:

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

经验教训是,当您要排除某些内容时,请仔细检查所有依赖项,以确保将其从所有位置排除。gradle依赖输出可以得到改进以减少误导…



 类似资料:
  • 我在Jetty上使用Spring Boot,似乎我不能在Gradle构建文件中排除所有的Tomcat依赖项。 build.gradle的相关部分: 然而,当我运行时,Tomcat的一部分仍然存在,并导致WebSocket出现问题: 为什么< code > spring-boot-starter-Tomcat 没有被排除在< code > spring-boot-starter-web 之外?

  • 问题内容: 我遇到一个问题,其中同一类的多个版本显示在我的类路径中。有问题的班级是。我要使用的版本由引入。但是,我们还使用了Jira rest客户端库,该库依赖于较旧版本的jersey(),该版本包含捆绑在jar中的java.ws软件包。 这是构建文件中的示例片段: 我无法删除它,因为它使用了与新版本不同的软件包名称,并且会导致在Jira客户端中找不到类def的异常。 据我所知,目前我的选择是:

  • 我试图用JUnit和SLF4J测试来测试记录器的行为,这是“SLF4J的一个测试实现,它将日志消息存储在内存中,并提供检索它们的方法”。 我有一些将SLF4J作为传递依赖项的依赖项。我试图将SLF4J从我的测试配置中的所有依赖项中排除,但我仍然需要它来进行SLF4J测试。 我可以通过下面的代码将SLF4J排除在所有内容之外,但这显然也将它排除在我需要的SLF4J测试之外。 由于SLF4J是我的许多

  • 问题内容: 我有一个项目,该项目依赖于由供应商控制的工件。该工件包含一些我依赖的类,其中一些类较旧并且会引起问题。有没有办法让Maven自动扩展jar,删除类并将它们重新打包为依赖项?我会举一个例子。 所以- 我需要使用在项目网站,但我需要使用从神器。我无法修改Supplier:artifact或us:dependency。 有任何想法吗?! 问题答案: 从版本2.0.9开始,maven保留了类路

  • 是否有一种方法可以使用Gradle从一组中排除特定的jar?我尝试了下面的代码,但这删除了该组的所有jar

  • 我想使用第三方供应商的jar。但是在这个jar中,我有Java包的旧版本我需要找到一些方法将包从主项目中排除。像这样的东西: 你能推荐一些解决方案吗?

  • 我在我的项目中遇到了依赖关系冲突的问题。特别是,slf4j日志记录有两种实现:slf4j-简单和logback-经典,我得到了 在运行时。 logback-classic对我来说是必备的依赖项(因为dropwizard),但slf4j-simple不是真的,我想把它从我的uber项目中去掉。只是没那么容易。 我的“uber jar”依赖于“small jar”,而“small-jar”又依赖于“s