Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 3 MVC resources and tag <mvc:resources />

Tags:

I'm having some problems with the tag (Spring 3.0.5). I want to add images to my web application, but it doesnt work.

Here is part of my beans config:

<mvc:annotation-driven/> <mvc:default-servlet-handler default-servlet-name="ideafactory"/> <mvc:resources mapping="/resources/**" location="/, classpath:/WEB-INF/public-resources/" cache-period="10000" /> 

Trying to add an image in a jsp file:

<img src="<c:url value="/resources/logo.png" />" alt="Idea Factory" /> 

First of all, I don't know really where to store the resources (src/main/resources/public-resources? src/main/webapp/WEB-INF/public-resources?). Secondly, this config does not work, I can't see the image. What's wrong?

Thanks!

EDIT: the solution given here: Spring Tomcat and static resources and mvc:resources doesn't work either... Added without success.

EDIT 2: I tried to remove the mvc:resource tag and let only the mvc:default-servlet-handler> one, gave me infinite loop and stackoverflow... o_O (Serving static content with Spring 3)

like image 963
Nanocom Avatar asked Nov 19 '11 15:11

Nanocom


1 Answers

Found the error:

Final xxx-servlet.xml config:

<mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> 

Image in src/webapp/resources/logo.png

Works!

like image 102
Nanocom Avatar answered Nov 15 '22 18:11

Nanocom