我正在使用 Spring-boot 开发一个 Web 应用程序,它运行良好。
我一直在我的浏览器上编辑和测试它,就像它已部署到服务器上一样。
但现在我想生成我的war文件,并根据Spring's documentation here ,我必须将 tomcat 依赖项标记为已提供。问题是我在 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>
最佳答案
使用最新的父版本:
<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>
注意:如果您的父版本不同,您可以应用完全相同的过程并再次发现未声明的嵌入式依赖项(可能有不同的版本),然后按提供的方式重新声明它。
关于spring - 这是我的 spring-boot-starter-tomcat 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35983302/