1. The purpose of this post
This post would demo how to package the springboot app as a WAR file, and then it can be deployed to tomcat.
- springboot 1.x and 2.x(for example 2.1.5.RELEASE)
3. The solution
3.1 Change the build plugins in your POM
We must add the maven-war-plugin to your POM:
3.2 Add some settings to your POM
3.3 Add some dependencies to your POM
3.3 The whole POM.xml
3.4 Change your Main class
The main class of your springboot app must do some changes as follows:
The key points are:
- extends SpringBootServletInitializer to make your app known by tomcat web container
- override configure method to simply register our class as a configuration class of the application
3.5 Build your WAR file
Then you should get a WAR file in your target directory like this:
3.6 Deploy your WAR file to tomcat
Just put your springboot2-jdbctemplate-exec.war in the webapps of your tomcat directory.
start your tomcat :
Wait for a while and then visit the web like this:
Remember to add the springboot2-jdbctemplate-exec to your url address.