[英]springboot embedded tomcat and tomcat-embed-jasper
I sometimes see these following declaration in pom.xml...我有时会在 pom.xml 中看到以下声明...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
....
as you can see, spring-boot-starter-web was declared as well as tomcat-embed-jasper.如您所见,声明了 spring-boot-starter-web 以及 tomcat-embed-jasper。
isn't it spring-boot-starter-web already have an embedded tomcat? spring-boot-starter-web 不是已经有一个嵌入式 tomcat 了吗? why some developers still declare tomcat-embed-jasper along with boot-starter-web?
为什么有些开发人员仍然声明 tomcat-embed-jasper 和 boot-starter-web? or is there any reason?
或者有什么理由吗?
As you said, the spring-boot-starter-web
includes the spring-boot-starter-tomcat
.正如您所说,
spring-boot-starter-web
包括spring-boot-starter-tomcat
。 You could check it here你可以在这里查看
The spring-boot-starter-tomcat
includes the tomcat-embed-core
. spring-boot-starter-tomcat
包括tomcat-embed-core
。 You could check it here你可以在这里查看
But, seems like tomcat-embed-core
doesn't include tomcat-embed-jasper
.但是,似乎
tomcat-embed-core
不包括tomcat-embed-jasper
。 In fact, is tomcat-embed-jasper
who includes dependency with tomcat-embed-core
.事实上,是
tomcat-embed-jasper
包含了对tomcat-embed-core
依赖。 Check it here 在这里检查
Anyway, the tomcat-embed-jasper
is marked as provided
, so indicates that you expect the JDK or a container to provide the dependency at runtime.无论如何,
tomcat-embed-jasper
被标记为provided
,因此表明您希望 JDK 或容器在运行时提供依赖项。 This scope is only available on the compilation and test classpath, and is not transitive.此范围仅在编译和测试类路径上可用,不可传递。
In conclusion, the spring-boot-starter-web
includes the tomcat embedded dependency but it doesn't includes the jasper embedded dependency, so that should be the reason to declare it separately.综上所述,
spring-boot-starter-web
包含tomcat内嵌依赖,没有包含jasper内嵌依赖,所以应该单独声明。
Also, remember that using Spring IO Platform as parent you are able to manage dependencies easily.另外,请记住,使用 Spring IO Platform 作为父级可以轻松管理依赖项。 To know more about this you could read my post
要了解更多信息,您可以阅读我的帖子
Hope it helps,希望能帮助到你,
Extended from jcgarcia's answer.从 jcgarcia 的回答扩展而来。
Even it is provided, but when you build as war, spring-boot-maven-plugin will include two more jar: ecj-3.12.3.jar tomcat-embed-jasper-8.5.23.jar即使提供了,但是当您构建为战争时,spring-boot-maven-plugin 将包含另外两个 jar:ecj-3.12.3.jar tomcat-embed-jasper-8.5.23.jar
To those who are still facing this error in 2022 with Java Version 17, Maven Version 3.0.0 and Package Jar.对于那些在 2022 年使用 Java 版本 17、Maven 版本 3.0.0 和 Package Jar 仍然面临此错误的人。 I also ran into the same issue just now, seems like even though we set
<scope>Provided</scope>
Maven is not picking up the jar.我刚才也遇到了同样的问题,似乎即使我们设置了
<scope>Provided</scope>
Maven 也没有拿起罐子。 What you can do instead is just take that completely off while adding the dependency and run the Maven to install dependencies again.您可以做的是在添加依赖项时完全取消它,然后运行 Maven 再次安装依赖项。 It will fix it for sure.
它肯定会修复它。 So your pom.xml file will go:-
所以你的 pom.xml 文件会去: -
From从
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
To到
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.