Deploy a Spring Boot application under Tomcat Web Server Container

Higthligths:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}

}

pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>



</dependencies>

Spring boot provides option to deploy the application as a traditional war file in servlet 3.x(without web.xml)supporting tomcat server.Please see spring boot documentation for this. I will brief what you need to do here.

step 1 : modify pom.xml to change the packaging to war:(that you already did)

<packaging>war</packaging>

step 2 : change your dependency

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-tomcat</artifactId>
   </dependency>

to

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

step 3 :modify your war name (if you need to avoid the version details appended with the war name) in pom.xml under <build> tag.

<build>
    <finalName>web-service</finalName>
.....

step 4 : run maven build to create war : clean install step 5 : deploy the generated war file web-service.war in tomcat and request url in browser http://<tomcat ip>:<tomcat port>/web-service/hello

 

here the project : http://gitlab.saic.it/root/spring-boot-war-tomcat