springboot-Quick guide to serve static HTML page and bootstrap from scratch with Spring Boot Web App
1. The purpose of this post
I would demo a quick guide to serve static HTML page and bootstrap from scratch with Spring Boot Web App.
2. Environments
springboot 1.x or 2.x
bootstrap 4.x
java 1.8+
3. Create a simple maven project
Create a simple maven project , its layout is as follows:
4. The pom.xml
Here we use springboot 1.5.9, you can use springboot 1.x or 2.x here
We add the springboot starter spring-boot-starter-web , it provides the spring mvc ability to this project
We add spring-boot-starter-tomcat to deploy and run in tomcat
We set the finalName of the build, to be used as the war file name
We use the maven-war-plugin to package the war file
5. The Main class of the springboot app
According to this document, the SpringBootServletInitializer and the configure method is used because:
The first step in producing a deployable war file is to provide a SpringBootServletInitializer subclass and override its configure method. Doing so makes use of Spring Framework’s Servlet 3.0 support and lets you configure your application when it is launched by the servlet container.
6. Install bootstrap
Download boostrap files from this site, and extract the css and js files to this project’s src/main/resources/static,just like this:
7. Develop an index html
Create a new file named index.html in src/main/resources/static/index.html
mention the relative path of css and js files, just use them as js/xxx.js or css/xxx.css