Skip to main content

Integrating Bootstrap with Spring MVC in Maven


We can integrate Bootstrap with Spring MVC in different ways. We are going to use one approach to do it. Bootstrap can be added as webjars. For this, put the following dependencies into the pom.xml.

<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.6</version>
</dependency>

You need to add a dependency for jQuery as well as follows.

<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.2.3</version>
</dependency>

Now you are ready to go. But before that, add the following line of code to your servlet.xml file

 <mvc:resources mapping="/webjars/**" location="/webjars/" />

Now add the following lines to your view pages within the head tag.

<link rel="stylesheet" href="webjars/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="webjars/bootstrap/3.3.6/css/bootstrap-theme.min.css">

Then add these in your view pages just before the </body> tag to improve performance. (This is instead of putting them under the head section)

<script src="webjars/jquery/2.2.3/jquery.min.js"></script>
<script src="webjars/bootstrap/3.3.6/js/bootstrap.min.js"></script>

Now you can freely use the bootstrap features from your web application in Spring MVC.


Comments

Popular posts from this blog

How to import the Public Certificate of one WSO2 product to the trust store of another?

To demonstrate this point, I will use the 2 products WSO2 API Manager 2.1.0 (referred as APIM from here onwards) and WSO2 Enterprise Integrator 6.1.1 (referred as EI from here onwards). When using EI as the Business Process Server during configuration of Workflows in APIM, one step to perform is to import the public certificate of EI to the truststore of APIM [1]. So now let's see how this can be done. Step 1: Go to <EI_HOME>/repository/resources/security/ folder and execute the following keytool command. This command is used to export the public certificate of EI as a certificate file called wso2carbon.cer. Since the default keystore in EI is wso2carbon.jks, we have specified it as the keystore and the default alias is wso2carbon. Provide wso2carbon as the keystore password when prompted as it is the default password. After executing the above command from within the security folder in EI, you will see that a file with the name of wso2carbon.cer is created...