Nitin Rathod
Nitin Rathod

Reputation: 163

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven' - Spring 4.3.7

I am tring to configure Spring MVC + Hibernate but when I use this "tx:annotation-driven" on my servlet-context.xml file, I get error descreibed in title.

My servlet-context file is as below. I am using Spring 4.3.7

<?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
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
    http://www.springframework.org/schema/tx/spring-tx-4.3.xsd" >

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<context:component-scan base-package="com.nitin.SpringDemo.controller" />

<beans:bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <beans:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>    
    <beans:property name="url" value="jdbc:oracle:thin:@localhost:1521:ORCL" />  
    <beans:property name="username" value="hr" /> 
    <beans:property name="password" value="hr" />  
</beans:bean>  



<!-- Hibernate 4 SessionFactory Bean definition -->
<beans:bean id="hibernate4AnnotatedSessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="annotatedClasses">
        <beans:list>
            <beans:value>com.nitin.SpringDemo.controller</beans:value>
        </beans:list>
    </beans:property>
    <beans:property name="hibernateProperties">
        <beans:props>
            <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
            </beans:prop>
            <beans:prop key="hibernate.show_sql">true</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>

<beans:bean id="ServiceInterface" class="com.nitin.SpringDemo.controller.SpringDao">
    <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>

<context:component-scan base-package="com.nitin.SpringDemo.controller" />

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

<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <beans:property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory" />
</beans:bean>

I am new at this i am trying to learn but this configuration is taking lot of time really frustrated now , please if you all can help.

Upvotes: 0

Views: 627

Answers (1)

Roman Puchkovskiy
Roman Puchkovskiy

Reputation: 11835

xsi:schemaLocation should contain hints to the XML file processor on where to physically obtain the xsd files that will be used to validate the XML. It is filled

with pairs of URI references (one for the namespace name, and one for a hint as to the location of a schema document defining names for that namespace name)

Citation comes from https://www.w3.org/TR/xmlschema-1/#schema-loc

So xsi:schemaLocation should contain pairs <schema-URI, physical-location-URI>. In your case, http://www.springframework.org/schema/tx/spring-tx-4.3.xsd is unpaired.

The attribute should look like

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
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"

(note that I inserted http://www.springframework.org/schema/tx as the penultimate component).

Upvotes: 1

Related Questions