Java springboot 嵌入式 tomcat 和 tomcat-embed-jasper

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42154614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:56:20  来源:igfitidea点击:

springboot embedded tomcat and tomcat-embed-jasper

javatomcatspring-boot

提问by tuty_fruity

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? why some developers still declare tomcat-embed-jasper along with boot-starter-web? or is there any reason?

spring-boot-starter-web 不是已经有嵌入式tomcat了吗?为什么有些开发人员仍然将 tomcat-embed-jasper 与 boot-starter-web 一起声明?或者有什么原因吗?

采纳答案by jcgarcia

As you said, the spring-boot-starter-webincludes the spring-boot-starter-tomcat. You could check it here

正如你所说,spring-boot-starter-web包括spring-boot-starter-tomcat. 你可以在这里查看

The spring-boot-starter-tomcatincludes the tomcat-embed-core. You could check it here

spring-boot-starter-tomcat包括tomcat-embed-core。你可以在这里查看

But, seems like tomcat-embed-coredoesn't include tomcat-embed-jasper. In fact, is tomcat-embed-jasperwho includes dependency with tomcat-embed-core. Check it here

但是,似乎tomcat-embed-core不包括tomcat-embed-jasper. 事实上,是tomcat-embed-jasper谁包括依赖于tomcat-embed-core. 在这里检查

Anyway, the tomcat-embed-jasperis 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.

无论如何,tomcat-embed-jasper被标记为provided,因此表明您希望 JDK 或容器在运行时提供依赖项。此范围仅在编译和测试类路径上可用,并且不可传递。

In conclusion, the spring-boot-starter-webincludes 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. To know more about this you could read my post

另外,请记住,使用 Spring IO Platform 作为父级,您可以轻松管理依赖项。要了解更多信息,您可以阅读我的帖子

Hope it helps,

希望能帮助到你,

回答by Surasin Tancharoen

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

即使提供了它,但是当您构建为 war 时,spring-boot-maven-plugin 将包含另外两个 jar : ecj-3.12.3.jar tomcat-embed-jasper-8.5.23.jar