- Mastering Spring 5.0
- Ranga Rao Karanam
- 177字
- 2021-07-02 22:12:21
Integrating Spring MVC with Bootstrap
One of the approaches to using Bootstrap in a web application is to download the JavaScript and CSS files and make them available in their respective folders. However, this would mean that every time there is a new version of Bootstrap, we would need to download and make it available as part of the source code. The question is this--is there a way that we can introduce Bootstrap or any other static (JS or CSS) libraries using dependency management such as Maven?
The answer is WebJars. WebJars are client-side JS or CSS libraries packaged into JAR files. We can use Java build tools (Maven or Gradle) to download and make them available to the application. The biggest advantage is that WebJars are resolve transitive dependencies.
Now let's use Bootstrap WebJar and include it in our web application. The steps involved are as follows:
- Add Bootstrap WebJars as a Maven dependency
- Configure the Spring MVC resource handler to deliver static content from WebJar
- Use Bootstrap resources (CSS and JS) in the JSP