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

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

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

nwo49xxi

nwo49xxi1#

您可以在pom文件中排除:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>tomcat-embed-el</artifactId>
            <groupId>org.apache.tomcat.embed</groupId>
        </exclusion>
        <exclusion>
            <artifactId>tomcat-embed-core</artifactId>
            <groupId>org.apache.tomcat.embed</groupId>
        </exclusion>
        <exclusion>
            <artifactId>tomcat-embed-websocket</artifactId>
            <groupId>org.apache.tomcat.embed</groupId>
        </exclusion>
    </exclusions>
</dependency>

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

atmip9wb

atmip9wb2#

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

<!-- Removing the dependency for the embedded tomcat -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>

字符串

ma8fv8wu

ma8fv8wu3#

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

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-websocket</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <scope>provided</scope>
    </dependency>

字符串

kulphzqa

kulphzqa4#

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

<exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
</exclusions>

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

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
</dependencies>

q3aa0525

q3aa05255#

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludeGroupIds>org.apache.tomcat.embed</excludeGroupIds>
    </configuration>
</plugin>

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

uqxowvwt

uqxowvwt6#

最好是提一下

pom.xml文件中提供的范围

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

字符串

f87krz0w

f87krz0w7#

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
        <exclusions>
           <exclusion>
              <artifactId>tomcat-embed-el</artifactId>
              <groupId>org.apache.tomcat.embed</groupId>
           </exclusion>
           <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-tomcat</artifactId>
           </exclusion>
        </exclusions>       
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>        
        <exclusions>
           <exclusion>
              <artifactId>tomcat-embed-el</artifactId>
              <groupId>org.apache.tomcat.embed</groupId>
           </exclusion>
           <exclusion>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-tomcat</artifactId>
           </exclusion>
        </exclusions>
    </dependency>   
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

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

相关问题