Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

springboot embedded tomcat and tomcat-embed-jasper

Tags:

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>     .... 

as you can see, spring-boot-starter-web was declared as well as 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?

like image 775
tuty_fruity Avatar asked Feb 10 '17 08:02

tuty_fruity


People also ask

Why we use Tomcat embed Jasper in Spring boot?

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.

Is Tomcat server embedded in Spring boot?

Spring Boot is a popular Java-based framework to develop microservices. By default, the Spring Tool Suite (STS) IDE -- which is used to build a Spring Boot application -- will automatically create an embedded Tomcat server with the microservices developed each time a build or deployment occurs.

Why do we need Tomcat Jasper?

It is an advanced Java compiler which will load all dependencies from the Tomcat class loader, which will help tremendously when compiling on large installations with tens of JARs. On fast servers, this will allow sub-second recompilation cycles for even large JSP pages.

Which version of Tomcat is embedded in Spring boot?

Tomcat 7 & 8.0 work with Spring Boot, but the default is to use Tomcat 8.5. If you cannot use Tomcat 8.5 (for example, because you are using Java 1.6) you will need to change your classpath to reference a different version.


2 Answers

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

The spring-boot-starter-tomcat includes the tomcat-embed-core. You could check it 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

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.

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.

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

Hope it helps,

like image 173
jcgarcia Avatar answered Sep 19 '22 08:09

jcgarcia


Extended from jcgarcia's answer.

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

like image 39
Surasin Tancharoen Avatar answered Sep 18 '22 08:09

Surasin Tancharoen