Spring Boot 如何在Sping Boot 应用程序中排除嵌入的Tomcat

waxmsbnn  于 2023-11-17  发布在  Spring
关注(0)|答案(7)|浏览(165)

我们如何从Sping Boot 应用程序中排除嵌入式Tomcat服务器,以便我们可以在JBoss服务器上运行该jar?

nwo49xxi

nwo49xxi1#

您可以在pom文件中排除:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-web</artifactId>
  4. <exclusions>
  5. <exclusion>
  6. <artifactId>tomcat-embed-el</artifactId>
  7. <groupId>org.apache.tomcat.embed</groupId>
  8. </exclusion>
  9. <exclusion>
  10. <artifactId>tomcat-embed-core</artifactId>
  11. <groupId>org.apache.tomcat.embed</groupId>
  12. </exclusion>
  13. <exclusion>
  14. <artifactId>tomcat-embed-websocket</artifactId>
  15. <groupId>org.apache.tomcat.embed</groupId>
  16. </exclusion>
  17. </exclusions>
  18. </dependency>

字符串
您可以通过屏幕截图关注此link
嵌入式servlet容器上的Spring文档

展开查看全部
atmip9wb

atmip9wb2#

您可以按如下方式修改POM.xml文件:

  1. <!-- Removing the dependency for the embedded tomcat -->
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-tomcat</artifactId>
  9. </exclusion>
  10. </exclusions>

字符串

ma8fv8wu

ma8fv8wu3#

另一种方法是将tomcat依赖项的scope标记为在pom.xml中提供的:

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-web</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.apache.tomcat.embed</groupId>
  7. <artifactId>tomcat-embed-websocket</artifactId>
  8. <scope>provided</scope>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.apache.tomcat.embed</groupId>
  12. <artifactId>tomcat-embed-core</artifactId>
  13. <scope>provided</scope>
  14. </dependency>

字符串

展开查看全部
kulphzqa

kulphzqa4#

<artificatId>的依赖项中添加<exclusions>标记为'spring-boot-starter-web'

  1. <exclusions>
  2. <exclusion>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-tomcat</artifactId>
  5. </exclusion>
  6. </exclusions>

字符串
你的最终依赖应该看起来像这样:

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-web</artifactId>
  5. <exclusions>
  6. <exclusion>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-tomcat</artifactId>
  9. </exclusion>
  10. </exclusions>
  11. </dependency>
  12. </dependencies>

展开查看全部
q3aa0525

q3aa05255#

  1. <plugin>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-maven-plugin</artifactId>
  4. <configuration>
  5. <excludeGroupIds>org.apache.tomcat.embed</excludeGroupIds>
  6. </configuration>
  7. </plugin>

字符串
您可以查看这篇文章。

uqxowvwt

uqxowvwt6#

最好是提一下

pom.xml文件中提供的范围

在基于Sping Boot Maven的应用程序中排除嵌入式Tomcat服务器。

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-tomcat</artifactId>
  4. <scope>provided</scope>
  5. </dependency>

字符串

f87krz0w

f87krz0w7#

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-validation</artifactId>
  4. <exclusions>
  5. <exclusion>
  6. <artifactId>tomcat-embed-el</artifactId>
  7. <groupId>org.apache.tomcat.embed</groupId>
  8. </exclusion>
  9. <exclusion>
  10. <groupId>org.springframework.boot</groupId>
  11. <artifactId>spring-boot-starter-tomcat</artifactId>
  12. </exclusion>
  13. </exclusions>
  14. </dependency>
  15. <dependency>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-web</artifactId>
  18. <exclusions>
  19. <exclusion>
  20. <artifactId>tomcat-embed-el</artifactId>
  21. <groupId>org.apache.tomcat.embed</groupId>
  22. </exclusion>
  23. <exclusion>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-tomcat</artifactId>
  26. </exclusion>
  27. </exclusions>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-tomcat</artifactId>
  32. <scope>provided</scope>
  33. </dependency>

字符串
对于Sping Boot 2.7.12版本的示例在这里。如果您使用验证,不要忘记从排除。PS:不要从目标文件夹复制war文件。它有lib提供的文件夹。使用maven-war-plugin并从其输出文件夹复制。

展开查看全部

相关问题