Kau*_*ain 5 java eclipse spring spring-mvc maven
我有一个使用maven创建的Spring项目。以下是我的目录结构。
我想将CSS图像添加到该项目。为此,我在web-inf目录中创建了一个resources文件夹,并将图像放置在那里。在我的调度程序servlet xml中,我添加了3行有关mvc的内容。一行在xmlns:mvc中,另外两行是模式位置中的最后两行:
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"/>
Run Code Online (Sandbox Code Playgroud)
当我添加以上3行时,我的项目无法正常工作。我得到错误:
description The requested resource is not available.
Run Code Online (Sandbox Code Playgroud)
如果我从bean声明中删除了mvc行,并运行没有图片/ css的项目,则该项目将运行。
谁能帮我这个?如果上述方法不是将CSS和图像添加到Spring MVC项目的方法,请指出正确的方法。
非常感谢!
你需要一个小的改变即。
<mvc:resources mapping="/resources/**" location="/resources/" />
Run Code Online (Sandbox Code Playgroud)
加上根据标准 maven 项目创建一个新文件夹并将您的资源放在此
src/main/resources
Run Code Online (Sandbox Code Playgroud)