springboot嵌入式tomcat和tomcat-embed-jasper [英] springboot embedded tomcat and tomcat-embed-jasper
问题描述
我有时会在pom.xml中看到以下声明......
I sometimes see these following declaration in 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>
....
如你所见,spring-boot-starter-web was声明为
为tomcat-embed-jasper。
as you can see, spring-boot-starter-web was declared as well as tomcat-embed-jasper.
是不是spring-boot-starter-web已经有嵌入式tomcat?
为什么有些开发人员仍然使用boot-starter-web声明tomcat-embed-jasper?或者有什么理由?
isn't it spring-boot-starter-web already have an embedded tomcat? why some developers still declare tomcat-embed-jasper along with boot-starter-web? or is there any reason?
推荐答案
如你所说, spring-boot-starter-web
包含 spring-boot-starter-tomcat
。您可以查看这里
As you said, the spring-boot-starter-web
includes the spring-boot-starter-tomcat
. You could check it here
spring-boot-starter-tomcat
包含 tomcat -embed芯
。您可以查看这里
但是,似乎 tomcat-embed-core
不包括 Tomcat的嵌入-碧玉
。实际上, tomcat-embed-jasper
包含与 tomcat-embed-core
的依赖关系。检查它 here
But, seems like tomcat-embed-core
doesn't include tomcat-embed-jasper
. In fact, is tomcat-embed-jasper
who includes dependency with tomcat-embed-core
. Check it here
无论如何, tomcat-embed-jasper
标记为提供
,表示您希望JDK或容器在运行时提供依赖项。此范围仅在编译和测试类路径中可用,并且不可传递。
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. This scope is only available on the compilation and test classpath, and is not transitive.
总之, spring-boot-starter-web
包含tomcat嵌入式依赖项,但它不包含jasper嵌入式依赖项,因此应该单独声明它。
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 IO Platform作为父级,您可以轻松地管理依赖项。要了解更多信息,请阅读我的帖子
Also, remember that using Spring IO Platform as parent you are able to manage dependencies easily. To know more about this you could read my post
希望有所帮助,
这篇关于springboot嵌入式tomcat和tomcat-embed-jasper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!