Henrique Ordine
Henrique Ordine

Reputation: 3337

Which is my spring-boot-starter-tomcat dependency

I'm developing a web application with Spring-boot and it's all been working quite well.

I've been editing and testing it on my browser like it's been deployed to a server.

But now I want to generate my war file, and according to Spring's documentation here, I have to mark the tomcat dependecies as provided. The thing is that I don't see this dependency anywhere in my pom.xml.

Question: Which dependency should I mark as provided?

These are the ones I actually have in my 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>

Upvotes: 1

Views: 14315

Answers (1)

A_Di-Matteo
A_Di-Matteo

Reputation: 27812

Using the latest parent version:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

And running a dependency tree on the project:

mvn dependency:tree

To check which declared dependency is bringing in the embedded Tomcat server, you get as part of the output:

[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   

Which means the declared spring-boot-starter-thymeleaf dependency is bringing it, in particular is bringing org.springframework.boot:spring-boot-starter-tomcat:1.3.3.RELEASE in.

You can esplicitely declared it as provided which will then influence as well projects dependencies management and as such the war packaging.

Hence, add to you pom:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <version>1.3.3.RELEASE</version>
    <scope>provided</scope>
</dependency>

Note: if your parent version is different, you can apply exactly the same process and spot the undeclared embedded dependency again (which could have a different version), then re-declare it as provided.

Upvotes: 1

Related Questions