Java SpringMVCServlet错误
在尝试使用SpringMVC、addMinutes.jsp和hello.jsp访问我的页面时,我遇到以下错误。我只能访问根本地主机,但如果导航到某个页面,则会出现以下错误:Java SpringMVCServlet错误,java,xml,spring,jsp,spring-mvc,Java,Xml,Spring,Jsp,Spring Mvc,在尝试使用SpringMVC、addMinutes.jsp和hello.jsp访问我的页面时,我遇到以下错误。我只能访问根本地主机,但如果导航到某个页面,则会出现以下错误: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/config/servlet-config.xml] is
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/config/servlet-config.xml] is invalid;
nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
我在网上搜索过,我认为我的xml=”“
链接可能是错误的,但我是直接从pluralsight.com教程中得到的。我是JAVA MVC新手,所以这对我来说是陌生的。任何帮助都将不胜感激
这是我的servlet-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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.pluralsight.controller"></context:component-scan>
<!--
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>-->
<bean class="org.springframework.web.servlet.view.InteralResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
</beans>
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
fitTrackerServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/config/servlet-config.xml
fitTrackerServlet
*.html
Web应用程序创建的原型
将mvc
和context
架构位置添加到应用程序上下文文件的bean
部分
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
这个怎么样,基本上它缺少一些名称空间xmlns:p=”http://www.springframework.org/schema/p"
这里有一个用于spring配置的工作头模板:
<?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"
xmlns:p="http://www.springframework.org/schema/p"
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">
...
</beans>
...
另外,请确保您正在运行Spring>=3的最新版本(否则,mvc
和p
-名称空间将不起作用),并且您的类路径中有所有必要的Spring JAR
如果您需要经常编辑Spring配置文件,安装Spring工具套件(STS)是一个很好的帮助,因为它有模板和非常有用的“名称空间”选项卡,用于在Spring配置文件中配置必要的XML名称空间
花几个小时学习XML也不会有什么坏处。通过这些更改,我得到了三个错误:未找到上下文声明:组件扫描,p:前缀未绑定到bean,以及在此行找到多个注释:-schema_reference.4:未能读取模式文档“mvc/spring-mvc-2.0.xsd”,因为1)找不到文档;2) 文件无法读取;3) 文档的根元素不是。-cvc complex type.2.4.c:匹配的通配符是严格的,但找不到元素“mvc:注释驱动”的声明。还缺少上下文命名空间架构位置-请参阅update@C.Coggins你真的应该试着理解手头的问题,而不是诉诸于复制/粘贴的狂热。对于每个名称空间声明,都需要指定一个位置。你需要看看是否一切正常。@Bart,是的,我可以花下一个月的时间试图理解这些xml错误,或者我可以根据教程输入正确的xml地址,学习教程所教的内容,然后扩展到更大的主题。如果你在学习高等数学,在开始学习sin、切线等之前,你必须学会数到10。了解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"
xmlns:p="http://www.springframework.org/schema/p"
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">
...
</beans>