我有一个使用maven创建的Spring项目。以下是我的目录结构。
我想将CSS图像添加到该项目。为此,我在web-inf目录中创建了一个resources文件夹,并在其中放置了一个图像。在我的调度程序servlet xml中,我添加了3行关于mvc的内容。一行在xmlns:mvc中,另外2行是架构位置中的最后2行:
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“>
mvc xmlns和xsi位置较早不存在,我添加了它们,以便以下行可用:
<mvc:resources location="/resources/**" mapping="/resources"/>
当我添加以上3行时,我的项目无法正常工作。我得到了错误:
description The requested resource is not available.
如果我从bean声明中删除了mvc行,并运行没有图片/css的项目,则该项目将运行。
谁能帮我这个?如果上述方法不是将CSS和图像添加到Spring MVC项目的方法,请指出正确的方法。
非常感谢!
最佳答案
您需要一个零钱,即。
<mvc:resources mapping="/resources/**" location="/resources/" />
加上根据标准的maven项目创建一个新文件夹,并将您的资源放在此
src/main/resources