How can we exclude embedded Tomcat server from Spring Boot application so that we can run that jar on JBoss Server?
Asked
Active
Viewed 3.8k times
9
-
2You don't need to exclude it it will just run on the server AND be executable. – M. Deinum Dec 15 '17 at 07:23
-
Okay, that means even if we run jar on production server, in our case we are using Jboss on prod,will automatically deploy on jboss instead of Tomcat? – Deepesh Rathore Dec 15 '17 at 07:26
-
1I was assuming a `war` file and not a `jar` file. You should at least make the dependencies scoped `provided` so that they are moved to a different directory. That directory is used by Spring Boot but not when deploying the file. – M. Deinum Dec 15 '17 at 07:27
-
Incase of jar file what it gonna do, will it deploy on embedded Tomcat or ll it deploy on jboss. – Deepesh Rathore Dec 15 '17 at 07:28
5 Answers
14
You can exclude in pom file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>tomcat-embed-el</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
<exclusion>
<artifactId>tomcat-embed-core</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
<exclusion>
<artifactId>tomcat-embed-websocket</artifactId>
<groupId>org.apache.tomcat.embed</groupId>
</exclusion>
</exclusions>
</dependency>
You can follow this link with screenshots
-
When i run my application with above suggestion, it gives me error "Unregistering JMX-exposed beans on shutdown" – Tatkal Apr 11 '18 at 09:27
7
you can modify your POM.xml file as follows:
<!-- Removing the dependency for the embedded tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
aditya gupta
- 353
- 1
- 10
2
Another way is to mark the tomcat dependency's scope as provided in your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<scope>provided</scope>
</dependency>
jumping_monkey
- 3,799
- 2
- 28
- 42
0
Add the <exclusions> tag in dependency with <artificatId> as 'spring-boot-starter-web'
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
Your final dependency should look like:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
David Buck
- 3,594
- 33
- 29
- 34
P. S. Bhandari
- 11
- 2
0
Better to mention
scope as provided in pom.xml file
to exclude embedded tomcat server in spring boot maven based application.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Gautam Kumar
- 23
- 6