Skip to main content

How to Add Bootstrap Css and JQuery To Spring Boot MVC Application

How to add Bootstrap, Font-Awesome and Jquery to spring Boot Project

Introduction

Twitter Bootstrap is one of the most popular front-end frameworks for responsive web design and development.

Font Awesome provides us with scalable vector icons that can be customised. Needless to say, anything about Jquery, since it is the number 1 Javascript framework and has been so from last 10 years.

It is Imperative that for your Spring Boot MVC based application you will require either of the above technologies to make your web pages look better.

Add Maven Dependencies

We need to add dependency for

  • Jquery
  • Bootstrap
  • FontAwesome

Apart from above, we need to add a dependency for web jars locator which lets us locate the CSS and JS files without providing the exact version of files.

 

Annotations

Make sure you have either of the annotations in your Spring Boot
@SpringBootApplication
or
@EnableWebMvc

@SpringBootApplication is equivalent of using all three @Configuration, @EnableWebMvc and @ComponentScan
@SpringBootApplication = @Configuration + @EnableWebMvc+@ComponentScan

Add the reference in HTML pages

In the HTML page, you need to provide link to CSS and javascript src files location. Add the below head section in your *.html file
Note that the path doesn’t contain any specific version of CSS file or js files, thanks to web jars-locator dependency. That would mean that even if you change the version in your pom.xml there is no need to change any reference in HTML

Add the HTML

You can use any of the above CSS classes from bootstrap and font awesome or js files from Jquery with your HTML pages.

 

Run the application

For above code, I got the following output. Bootstrap button classes and icons from font-awesome have been applied to the buttons.

Follow this Video for reference

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami