I have a Spring project created using maven. The following is my directory structure.
I want to add css images to this project. For this, i created a resources folder inside the web-inf directory and placed an image there. To my dispatcher servlet xml, i added 3 lines, pertaining to mvc. One line is in the xmlns:mvc and the other 2 are the last 2 lines in the schema location:
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
The mvc xmlns and xsi locations were not present earlier, i added them so that the following line works:
<mvc:resources location="/resources/**" mapping="/resources"/>
When i add the above 3 lines, My project does not work. I get the error:
description The requested resource is not available.
If i remove the mvc lines from the beans declaration and run the project w/o images/css the project runs.
Can anyone help me with this? If the above method is not the way to add css and images to a spring mvc project, please point out to the correct way.
Thanks a lot!
You need a small change viz.
<mvc:resources mapping="/resources/**" location="/resources/" />
plus according to standard maven project create a new folder and put your resources in this
src/main/resources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With