title: Spring MVC not loading resources
body: <p>This is really frustrating I would appreciate some help with this as I have a deployment on coming weekend and suddenly the application has stopped working.
  I have a Spring 4.3.3 application hosted on Apache Tomcat 7 with JDK 1.7. The application was running fine when it suddenly stopped loading all the JS, CSS and image files with an HTTP Status code of 405 (Get Method not allowed). The only noticeable change that I did was update the Java installed on my laptop. I have even uninstalled that version of java but no benefit.</p>
  
  <p>The network tab of chrome shows the following result.</p>
  
  <p><a href="https://i.stack.imgur.com/O1vnh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O1vnh.png" alt="enter image description here"></a></p>
  
  <p>The error shown in Chrome browser is given below:</p>
  
  <pre><code>General:
      Request URL:http://localhost:8080/TractivityPhase3/resources/ui/jquery-ui.css
      Request Method:GET
      Status Code:405 Method Not Allowed
      Remote Address:[::1]:8080
      Referrer Policy:no-referrer-when-downgrade
  Response Headers:
      view source
      Allow:POST
      Content-Length:96
      Content-Type:text/html;charset=ISO-8859-1
      Date:Mon, 10 Jul 2017 12:12:49 GMT
      Server:Apache-Coyote/1.1
  Request Headers:
      view source
      Accept:text/css,*/*;q=0.1
      Accept-Encoding:gzip, deflate, br
      Accept-Language:en-US,en;q=0.8
      Connection:keep-alive
      Cookie:JSESSIONID=8F5257A38E3AC1FBBD4BCF0A869A5A05
      Host:localhost:8080
      Referer:http://localhost:8080/TractivityPhase3/login
      User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
  </code></pre>
  
  <p>My web.xml code is given below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
      &lt;display-name&gt;Spring MVC Application&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;createIdeaPublic&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
          &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
          &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
          &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
      &lt;display-name&gt;Tractivity&lt;/display-name&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;120&lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;servlet&gt;
        &lt;servlet-name&gt;Tractivity&lt;/servlet-name&gt;
        &lt;servlet-class&gt;
           org.springframework.web.servlet.DispatcherServlet
        &lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
     &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;Tractivity&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
     &lt;listener&gt;
          &lt;listener-class&gt;com.soft.utils.SessionListener&lt;/listener-class&gt;
      &lt;/listener&gt;
     &lt;error-page&gt;
      &lt;location&gt;/jsp/components/jspError.jsp&lt;/location&gt;
      &lt;/error-page&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The dispatcher-Servlet configuration is given below.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "&gt;
  
     &lt;context:component-scan base-package="com.soft.controllers, com.soft.ajax,com.soft.services, com.soft.daos" /&gt;
  
     &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
        &lt;property name="prefix" value="/jsp/templates/" /&gt;
        &lt;property name="suffix" value=".jsp" /&gt;
     &lt;/bean&gt;
  
      &lt;mvc:resources mapping="/resources/ui/**" location="/resources/ui/jquery-ui-1.12.1.custom/" /&gt;
      &lt;!-- &lt;mvc:resources mapping="/resources/ui/**" location="/resources/ui/jquery-ui-1.12.1.custom/" /&gt; --&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;mvc:annotation-driven/&gt;
      &lt;!-- 
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
          &lt;property name="url" value="${jdbc.url}"/&gt;
          &lt;property name="username" value="${jdbc.username}"/&gt;
          &lt;property name="password" value="${jdbc.password}"/&gt;
      &lt;/bean&gt; --&gt;
  
      &lt;aop:aspectj-autoproxy proxy-target-class="true"/&gt;
  
      &lt;bean id="dataSource" class="com.soft.utils.SecureDataSource"&gt;
          &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
          &lt;property name="url" value="${jdbc.url}"/&gt;
           &lt;property name="username" value="${jdbc.username}"/&gt;
          &lt;property name="password" value="${jdbc.password}"/&gt; 
      &lt;/bean&gt;
  
      &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
          &lt;constructor-arg ref="dataSource"&gt;&lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
  
      &lt;context:property-placeholder location="jdbc.properties, security.properties"/&gt;
  
     &lt;!--  &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
           setting maximum upload size
          &lt;property name="maxUploadSize" value="100000" /&gt;
      &lt;/bean&gt; --&gt;
  
      &lt;bean id="emailer" class="com.soft.utils.Emailer"&gt;
      &lt;property name="host" value="localhost"/&gt;
          &lt;property name="from" value="CIActivityTracker@abc.com"/&gt;
          &lt;property name="username" value="368649312300d9094a62" /&gt;
          &lt;property name="password" value="cbe8181247b9785036ee" /&gt;    
  
      &lt;/bean&gt;
  
      &lt;bean id="ldapContextSource" class="com.soft.utils.LdapContextSource"&gt;
          &lt;property name="url" value="${ldap.url}"/&gt;
          &lt;property name="base" value="${ldap.base}"/&gt;
          &lt;property name="userDn" value="${ldap.userDn}"/&gt;
          &lt;property name="pass" value="${ldap.password}"/&gt;
          &lt;property name="referral" value="follow"/&gt;
          &lt;property name="ldapAuthentication" value="${ldap.authentication}"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Aspect --&gt;
      &lt;bean id="logAspect" class="com.soft.aspect.LoggingAspect" /&gt;
  
  
      &lt;bean id="simpleJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;
          &lt;property name="targetObject" ref="quartzExample" /&gt;
          &lt;property name="targetMethod" value="printMessage" /&gt;
      &lt;/bean&gt;
      &lt;bean id="quartzExample" class="com.soft.quartz.QuartzExample"&gt;
          &lt;property name="dbcViewName" value="${dbc.view}"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dailyTrigger"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"&gt;
          &lt;property name="jobDetail" ref="simpleJobDetail" /&gt;
          &lt;property name="cronExpression" value="0 0/2 * * * ? *" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="weeklyTrigger"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"&gt;
          &lt;property name="jobDetail" ref="simpleJobDetail" /&gt;
          &lt;property name="cronExpression" value="0/6 * * ? * L *" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="monthlyTrigger"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"&gt;
          &lt;property name="jobDetail" ref="simpleJobDetail" /&gt;
          &lt;property name="cronExpression" value="0/6 * * L * ? *" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="quarterlyTrigger"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"&gt;
          &lt;property name="jobDetail" ref="simpleJobDetail" /&gt;
          &lt;property name="cronExpression" value="0/1 * * L MAR,JUN,SEP,DEC ? *" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="annualTrigger"  class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"&gt;
          &lt;property name="jobDetail" ref="simpleJobDetail" /&gt;
          &lt;property name="cronExpression" value="0/1 * * 31 12 ? *" /&gt;
      &lt;/bean&gt;
  
      &lt;bean  class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;
          &lt;property name="triggers"&gt;
              &lt;list&gt;
  &lt;!--                &lt;ref bean="dailyTrigger" /&gt; --&gt;
                  &lt;ref bean="dailyTrigger" /&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I have temporarliy fixed the issue by adding the following to web.xml. However, I would like a clean way of handling it through the Dispatcher Servlet's  tag.</p>
  
  <pre><code>&lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.js&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.css&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.PNG&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.png&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.gif&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.ico&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  </code></pre>