我是Spring MVC框架的新手,并试图学习,但是抛出了一个例外。原因是什么?
看来我的dispatcher-servlet.xml
文件中有一个错误:
<?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: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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<annotation-driven />
<context:component-scan base-package="kz.controller" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans:beans>
我的控制器类是注释驱动的,但是正在抛出此错误:
http状态500 -
Servlet.init()
用于Servlet调度器抛出异常类型异常报告
消息
Servlet.init()
for Servlet调度员投掷异常描述服务器遇到了内部错误,阻止其满足此请求。
异常
javax.servlet.ServletException
:Servlet.init()
for servlet调度员抛出异常org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException
:XML文档中的第23行来自ServletContext
资源[/WEB-INF/dispatcher-servlet.xml
]无效;
您的XML不正确。您在豆名称空间下定义了bean名称空间。正确的XML是这样的:
<?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: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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<annotation-driven />
<context:component-scan base-package="kz.controller" />
<beans:bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<beans:property name="prefix" value="/WEB-INF/jsp/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
通常在春季应用程序中,beans架构为默认值,因此如果您将beans架构更改为默认值会更好,那么您可以删除所有" beans:",然后添加" mvc:"到其他标签中。
检查错误消息。它说File/Web-inf/dispatcher-servlet.xml不是有效的XML文件。使用IDE(Eclipse,Intellij,Netbeans等)打开文件,应该说出为什么文件无效。
尤其是错误在
中</bean>
</beans:beans>
您不需要</bean>
。
底线,使用良好的IDE!我们在60中不再需要使用打孔卡&amp;希望我们的代码正确:)。