这是我的spring-boot-starter-tomcat依赖项

时间:2016-03-14 09:05:54

标签: spring maven tomcat spring-boot maven-dependency

我正在使用Spring-boot开发一个Web应用程序,并且它一直运行良好。

我一直在我的浏览器上编辑和测试它,就像它被部署到服务器一样。

但现在我想生成我的war文件,根据Spring's documentation here,我必须将tomcat dependecies标记为提供。问题是我在pom.xml中的任何地方都没有看到这种依赖。

问题:我应该将哪个依赖关系标记为已提供?

这些是我在pom.xml中实际拥有的那些:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:1)

使用最新的父版本:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

在项目上运行dependency tree

mvn dependency:tree

要检查嵌入式Tomcat服务器中引入了哪个声明的依赖项,您将获得输出的一部分:

[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.3.3.RELEASE:compile   
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.3.3.RELEASE:compile   
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.3.RELEASE:compile   
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.32:compile   
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.32:compile   
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.32:compile   
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.32:compile   

这意味着声明的spring-boot-starter-thymeleaf依赖项带来了它,特别是带来了org.springframework.boot:spring-boot-starter-tomcat:1.3.3.RELEASE

您可以将其明确地声明为provided,这将影响项目依赖关系管理以及war打包。

因此,加你pom:

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

注意:如果您的父版本不同,您可以应用完全相同的过程并再次发现未声明的嵌入式依赖项(可能有不同的版本),然后按照提供的方式重新声明它。

相关问题