Home > Mobile >  invalid; nested exception is org.xml.sax.SAXParseException; Expecting namespace 'http://www.spr
invalid; nested exception is org.xml.sax.SAXParseException; Expecting namespace 'http://www.spr

Time:11-23

I am working on a simple web application as a demo. And i am stuck at this error. Tomcat application server reports the following error on accessing the application context url. I couldn't figure what is the cause of this error.

mvn clean package builds the package fine

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/tx/spring-tx-4.3.xsd; lineNumber: 9; columnNumber: 38; TargetNamespace.1: Expecting namespace 'http://www.springframework.org/schema/data/jpa', but the target namespace of the schema document is 'http://www.springframework.org/schema/tx'.


Here's the dispatcherServlet-servlet.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"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/jdbc
             http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
             http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.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-4.3.xsd
             http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<context:component-scan base-package="org.charlie" />
<mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <property name="objectMapper" ref="jsonMapper"></property>
        </bean>
        <bean class="org.springframework.http.converter.xml.MappingJackson2xmlHttpMesssageConverter">
        <property name="objectMapper" ref="xmlMapper" />
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>
<bean id="jsonMapper" class="org.springframework.http.converter.json.Jackson2ObjMapperFactoryBean">
    <property name="simpleDateFormat" value="yyyy-MM-dd HH:mm:ss" />
</bean>

<bean id="xmlMapper" parent="jsonMapper">
    <property name="createXmlMapper" value="true"/>
</bean>

<mvc:resources mapping="/webjars/**" location="classpath:META-INF/resources/webjars/" />
<jpa:repositories base-package="org.charlie.repository" />
<jdbc:embedded-database id="dataSource" type="H2">
    <jdbc:script location="classpath:META-INF/sql/schema.sql" />
    <jdbc:script location="classpath:META-INF/sql/data.sql" />
</jdbc:embedded-database>

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="showSql" value="true" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean id="h2WebServer" class="org.h2.tools.Server" factory-method="createWebServer" init-method="start" destroy-method="stop">
    <constructor-arg value="-web,-webAllowOthers,-webDaemon,-webPort,8082" />
</bean>

</beans>


I am running tomcat version 9.0.30 spring version 5.3.13 java version 11

What could be issue?

if anymore details required, do let me. i will edit and add the details

CodePudding user response:

I would guess the problem is this line:

http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">

It should be something like this:

http://www.springframework.org/schema/data/jpa www.springframework.org/schema/data/jpa/spring-jpa-1.11.xsd">

Iam not a Spring expert, but I would guess this is a mapping from the namespace to a file that defines the Namespace

  • Related