Java Spring不提供静态内容

Java Spring不提供静态内容,java,spring,spring-mvc,Java,Spring,Spring Mvc,我试图使用SpringMVC:resource提供静态内容。问题是静态内容没有加载。当我检查我的请求时,我意识到HTTP 400错误的请求响应是从资源返回的(在我的例子和图像中) mvc-config.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/

我试图使用SpringMVC:resource提供静态内容。问题是静态内容没有加载。当我检查我的请求时,我意识到HTTP 400错误的请求响应是从资源返回的(在我的例子和图像中)

mvc-config.xml:

 <?xml version="1.0" encoding="UTF-8"?>

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.videovix"/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/"/>
        <property name="suffix" value=".jsp"/>
</bean>

</beans>
home.jsp

 <img src='<c:url value="/resources/img/library.png"></c:url>'/>
”/>
项目结构


我看了其他问题,但似乎没有一个能解决我的问题。导致此问题的原因是什么?如何解决此问题?

Spring注册一个
ResourceHttpRequestHandler
,用于在使用时处理资源

<mvc:resources mapping="/resources/**" location="/resources/"/>


此处理程序无法返回错误的400请求响应。您必须有一个带有映射处理程序的
@Controller
,该处理程序与
/resources[…]匹配。
。Spring将在资源处理程序之前检查
@Controller
处理程序。

如果您直接在浏览器地址栏中使用url,是否也会得到400?是的,也会返回400。您必须在某个位置有一个映射到
/resources
的控制器。让我们看看你的控制器映射。我无法重现你的问题。尝试调试
DispatcherServlet#doDispatch
方法,查看它如何处理请求。您忘记了您的
VideoWebservice
控制器。我试图找出原因,但是没有
值的
@RequestMapping
属性的优先级似乎高于其他属性。摆脱它或更改它。我将编辑问题并为我的控制器添加代码。这是一个奇怪的原因,正如您所看到的,在MyController中没有任何映射到资源的处理程序。@user2054833是否确定您没有向我们显示任何其他内容?在Spring配置或servlet配置中?我刚刚添加了web.xml文件的全部内容,唯一没有添加的是我的应用程序上下文xml文件以及hibernate的xml配置
 <img src='<c:url value="/resources/img/library.png"></c:url>'/>
<mvc:resources mapping="/resources/**" location="/resources/"/>