0
votes

The console throws me this error

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed

Line 23 in XML document from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml] is invalid

This is my servlet-context 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.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">

    
    <annotation-driven />

    <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" />
        
        
    <context:component-scan base-package="mvc.test.hib" />
    </beans:bean>

What i'm missing? i'm quite new to programming with spring/hibernate and there is things that still i don't understand very well

EDIT: additonal details, i'm using Spring tool suite, and the default MVC spring template project.

1
Last line should be </beans:beans> and not </beans:bean> (plural beans)Ori Dar
@orid Good catch. I was wondering how line 23 could be bad when the file only has 21 lines.Andreas

1 Answers

1
votes

The file you have posted is only 21 lines, whereas the error message you've given is saying that line 23 is invalid. Assuming that you lost a couple of line breaks in posting the file though, it looks like your missing a close tag for the <beans:beans> declaration. Add the following to the end of your file and the xml syntax will be valid.

</beans:beans>

You'll find it easier to write XML if you use an IDE (e.g. Eclipse) or a text editor which has inbuilt XML validation (e.g. Notepad++ with the XML Tools plugin). This will make it easier and faster for you to find syntax errors.