2017  Kodetalk | Feedback | Privacy Policy | Terms | About

javascript or css not recognized from maven spring web project

I created a new maven spring web application under eclipse and created a resources folder under webapp to use javascript and the css. And properly imported from the jsp files too.

<link rel="stylesheet" href="resources/css/bootstrap.min.css">

<link rel="stylesheet" href="resources/css/font-awesome.min.css">

<script type="text/javascript" src="resources/js/bootstrap.min.js"></script>

But when I build the application using maven install and deployed into the server the resources are not able recognized any of the the javascript or css files through the application.


Nothing wrong with your code, everything looks fine. May be you need to just override the below additional method into your annotated spring configuration class as below,

  1. @Override
  2. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  3. registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
  4. }

Note: Make sure the configuration class is extending the spring internal class 'WebMvcConfigurerAdapter' to override the method 'addResourceHandlers'.

Answer is