I have created spring boot web application, but I am unable to deploy spring boot web application WAR file on tomcat and I am able to run it as java application. How to run spring boot application as web service on tomcat. I am using following code. If it is possible to run on tomcat plz help me using annotations without using web.xml and with using web.xml.
@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);     }  }   Following code for rest controller
@RestController public class HelloWorld{     @RequestMapping(value = "/hello", method = RequestMethod.GET)    public ResponseEntity<String> get() {        return new ResponseEntity<String>("Hello World", HttpStatus.OK);    } }   Following Pom.xml I am using
<groupId>org.springframework</groupId> <artifactId>web-service</artifactId> <version>0.1.0</version>  <parent>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-parent</artifactId>     <version>1.3.0.RELEASE</version> </parent>  <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>          <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-beans</artifactId>     </dependency>         <dependency>         <groupId>org.springframework</groupId>         <artifactId>spring-webmvc</artifactId>     </dependency>     <dependency>         <groupId>com.googlecode.json-simple</groupId>         <artifactId>json-simple</artifactId>     </dependency>  </dependencies>  <properties>     <java.version>1.6</java.version> </properties>   <build>     <plugins>         <plugin>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-maven-plugin</artifactId>         </plugin>     </plugins> </build>  <repositories>     <repository>         <id>spring-releases</id>         <url>https://repo.spring.io/libs-release</url>     </repository> </repositories> <pluginRepositories>     <pluginRepository>         <id>spring-releases</id>         <url>https://repo.spring.io/libs-release</url>     </pluginRepository> </pluginRepositories> <packaging>war</packaging>   
                React + Spring Boot Microservices and SpringBy using Spring Boot application, we can create a war file to deploy into the web server. In this chapter, you are going to learn how to create a WAR file and deploy the Spring Boot application in Tomcat web server.
Here are two good documentations on how to deploy the Spring Boot App as a war file. 
You can follow this spring boot howto-traditional-deployment documentation -
Steps according to this documentation -
You update your application’s main class to extend    SpringBootServletInitializer.
The next step is to update your build configuration so that your project produces a war file rather than a jar file. <packaging>war</packaging>
Mark the embedded servlet container dependency as provided.
<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-tomcat</artifactId>     <scope>provided</scope> </dependency>  and one more way -
See this spring io documentation which outlines how to deploy the spring boot app to an application server.
Steps -
Change jar packaging to war.
Comment out the declaration of the spring-boot-maven-plugin plugin in your pom.xml
Add a web entry point into your application by extending SpringBootServletInitializer and override the configure method
Remove the spring-boot-starter-tomcat dependency and modfiy your spring-boot-starter-web dependency to
<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>
In your pom.xml, remove spring-beans and spring-webmvc dependencies. The spring-boot-starter-web dependency  will include those dependecies. 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With