559 Deploy Spring Boot Apps With Thymeleaf To Tomcat
559 Deploy Spring Boot Apps With Thymeleaf To Tomcat
Thymeleaf to Tomcat
We will create a WAR file and deploy the WAR to the Tomcat server.
This is known as a traditional deployment.
High-level steps
4. Deploy to Tomcat
For full details on this process, see the Spring Boot Reference Manual:
Section 92.1 Creating a Deployable WAR file
Working Example
I have a full working project. You can download this app and perform
test deployments to Tomcat
Download: deploy-spring-boot-war-with-thymeleaf-on-tomcat.zip
1. package com.luv2code.deploydemo.controller;
2.
3. import org.springframework.stereotype.Controller;
4. import org.springframework.web.bind.annotation.RequestMapping;
5.
6. @Controller
7. public class HelloWorldController {
8.
9. @RequestMapping("/test")
10. public String sayHello() {
11. return "hello";
12. }
13.
14. }
----
Detailed steps
<packaging>war</packaging>
The WAR packaging should appear just after your Maven coordinates
(group, artifact, version)
1. <groupId>com.luv2code</groupId>
2. <artifactId>deploydemo</artifactId>
3. <version>0.0.1-SNAPSHOT</version>
4. <packaging>war</packaging>
Make sure the Tomcat embedded does not interfere with external
Tomcat server
1. <dependency>
2. <groupId>org.springframework.boot</groupId>
3. <artifactId>spring-boot-starter-tomcat</artifactId>
4. <scope>provided</scope>
5. </dependency>
Create the WAR file with the command: mvn clean package
Wait for about 15-30 seconds for Tomcat to deploy your app. You will
know your app is deployed when you see a new folder created based
on your WAR file name. In our example, you will see a new directory
named: deploydemo
Replace <<deploydemo>> with the name of your WAR file if you are
using a different app