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 yes, using 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.

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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset