[英]Spring MVC is not recognizing mvc:resource in config file
更新:现在可以正常工作。 请按照评论。
这是我的Spring配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
<context:component-scan base-package="report.frontcontroller"/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"> <value>/WEB-INF/</value></property>
<property name="suffix"> <value>.jsp</value></property>
</bean>
</beans>
所有jar都包含在此项目中,并且配置文件如上所示。 我在这部分出现错误:
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
错误: *匹配的通配符是严格的,但未找到
mvc:resource
和mvc:annotation
*在此行找到多个注释: -cvc-complex-type.2.4.c:匹配的通配符是严格的,但是找不到元素'mvc:resources'的声明。 -schema_reference.4:无法读取架构文档' http://www.springframework.org/schema/mvc/spring- mvc-3.0.xsd',因为1)找不到文档; 2)无法读取文件; 3)文档的根元素不是。 在此行找到多个注释:* -cvc-complex-type.2.4.c:匹配的通配符很严格,但是找不到元素'mvc:resources'的声明。 -schema_reference.4:无法读取架构文档' http://www.springframework.org/schema/mvc/spring- mvc.xsd',因为1)找不到文档; 2)无法读取文件; 3)文档的根元素不是。
您可以尝试从GIT复制的以下配置-spring-mvc-showcase
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<task:annotation-driven />
</beans:beans>
更改为spring-mvc.xsd
更改为spring-mvc.xsd
spring-mvc-3.0.xsd
同样在所有其他位置进行更改。
请参考这里
编辑
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="report.frontcontroller" />
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.