更新:现在正常工作。请遵循评论。
这是我的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:匹配的通配符是strict,但是没有找到元素'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:匹配的通配符是strict,但是没有找到元素'mvc:resources'的声明。 - schema_reference.4:无法读取架构文档“http://www.springframework.org/schema/mvc/spring- mvc.xsd',因为1)找不到文件; 2)文件无法阅读; 3)文档的根元素 不是。
答案 0 :(得分:0)
您可以尝试下面从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>
答案 1 :(得分:-1)
更改为spring-mvc.xsd
至spring-mvc-3.0.xsd
。同样会更改所有其余位置。
参考here
修改强>
<?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>