1. The purpose of this post
I would demo how to build and deploy springboot web applications to apache tomcat.
2. Environments
- SpringBoot 2.x
- Thymeleaf 3.x
3. Key points
3.1 change your pom.xml
- Change embeded tomcat to provided tomcat:
- package your project as war
3.2 change your entry application class
Change your entry main class of springboot application to extends the SpringBootServletInitializer like this:
3.3 Externalize your application configuration files
If you want to externalize the configuration properties file of your web application, you can just do like this:
- Put your configuration file(application.properties) to your tomcat webconfig directory
- mkdir webconfig in your tomcat root dir
- cp your application.properties file to the webconf dir and remember its path
- change your catalina.sh like this:
3.4 Failed to get driver instance for jdbcUrl exception
Add this line to your application.properties: