Spring Not Finding Resource Files (Css, Jsp...)

Spring not finding resource files (css, jsp...)

The problem is that your requests for CSS and JS files are going through Dispatcher Servlet, which is not correct. Hence Spring won't find the mapping for those files it will not load them.

You need to add the resourceHandler for your application in the applicationContext.xml file as follows. This configuration will bypass the requests for CSS and JS files from the Dispatcher Servlet.

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

Hope this helps you... Cheers.

Please put following code in web.xml

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>

Why CSS from resources is not working in spring jsp page?

You need to put your resources in WebContent directory and not in src/main/resources

Please move your all static resources from src/main/resources to WebContent/resources directory.

This will allow spring to scan the static resource properly and then you can rebuild your application.

 <!-- the mvc resources tag does the magic -->
<mvc:resources mapping="/resources/**" location="/resources/" />

This will tell DispatcherServlet to delegate the resource scanning to correct servlet.

Add css file to resources but can not read it in Spring MVC 3.1

Finally, I changed spring mvc from 3.x to version 4, it worked.

Why can't Spring find resource files?

I finally figured it out by starting over from scratch. The only thing wrong was this line should not have been there in web.xml

<url-pattern>/</url-pattern>


Related Topics



Leave a reply



Submit