代码之家  ›  专栏  ›  技术社区  ›  Deepesh Rathore

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

  •  9
  • Deepesh Rathore  · 技术社区  · 8 年前

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

    5 回复  |  直到 8 年前
        1
  •  14
  •   campisano    6 年前

    您可以在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 带有屏幕截图

    Spring documentation on Embedded servlet container

        2
  •  7
  •   aditya gupta    8 年前

    您可以修改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>
    
        3
  •  2
  •   jumping_monkey    5 年前

    另一种方法是标记tomcat依赖项 scope provided 在您的 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>
    
        4
  •  0
  •   David Buck Richard Ferris    6 年前

    添加 <exclusions> 依赖项中的标记 <artificatId> 作为“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>
    
        5
  •  0
  •   Gautam Kumar    4 年前

    更值得一提的是

    pom中规定的范围。xml文件

    在基于spring boot maven的应用程序中排除嵌入式tomcat服务器。

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