Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link CSS and Images to Spring MVC maven Projcet

I have a Spring project created using maven. The following is my directory structure.

enter image description here

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!

like image 928
Kaushik Balasubramanain Avatar asked Jun 15 '13 14:06

Kaushik Balasubramanain


1 Answers

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
like image 160
Kalher Avatar answered Nov 15 '22 12:11

Kalher