Reputation: 235
As I am new to Spring MVC framework and trying to learn, but an exception is thrown. What could be the cause?
It seems like I have an error in my dispatcher-servlet.xml
file:
<?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>
My controller classes are annotation driven, but it is throwing this error:
HTTP Status 500 -
Servlet.init()
for servlet dispatcher threw exceptiontype Exception report
message
Servlet.init()
for servlet dispatcher threw exceptiondescription The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException
:Servlet.init()
for servlet dispatcher threw exceptionorg.springframework.beans.factory.xml.XmlBeanDefinitionStoreException
: Line 23 in XML document fromServletContext
resource [/WEB-INF/dispatcher-servlet.xml
] is invalid;
Upvotes: 0
Views: 9093
Reputation: 7722
Your XML is incorrect. You defined the bean namespace under the beans namespace. The correct XML is like this:
<?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>
Usually in spring applications the beans schema is the default so it would be even better if you would change the beans schema to be the default then you can delete all the "beans:" and add "mvc:" to the other tags.
Upvotes: 3
Reputation: 29827
Check the error message. It says that the file /WEB-INF/dispatcher-servlet.xml is not a valid xml file. Use an IDE (eclipse, intellij, netbeans, etc) to open the file and it should say why the file is invalid.
In particular the error is in
</bean>
</beans:beans>
you don't need </bean>
.
bottom line, use a good IDE! we're not any more in the '60 where we need to code with punch cards & hope our code is correct :).
Upvotes: 0