The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'

后端 未结 9 2303
夕颜
夕颜 2020-11-29 09:11

I am trying to configure JSF+Spring+hibernate and I\'m tying to run a test but when I use this \"tx:annotation-driven\" on my application-context.xml file, I get this error:

相关标签:
9条回答
  • 2020-11-29 09:44

    This is for others (like me :) ). Don't forget to add the spring tx jar/maven dependency. Also correct configuration in appctx is:

    xmlns:tx="http://www.springframework.org/schema/tx"
    

    xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"

    , by mistake wrong configuration which others may have

    xmlns:tx="http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
    

    i.e., extra "/spring-tx-3.1.xsd"

    xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"

    in other words what is there in xmlns(namespace) should have proper mapping in schemaLocation (namespace vs schema).

    namespace here is : http://www.springframework.org/schema/tx

    schema Doc Of namespace is : http://www.springframework.org/schema/tx/spring-tx-3.1.xsd

    this schema of namespace later is mapped in jar to locate the path of actual xsd located in org.springframework.transaction.config

    0 讨论(0)
  • 2020-11-29 09:47
    Any one can help for me!!!!!!!!!
    <?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:aop="http://www.springframework.org/schema/aop"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:jee="http://www.springframework.org/schema/jee"
            xmlns:lang="http://www.springframework.org/schema/lang"
            xmlns:p="http://www.springframework.org/schema/p"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:util="http://www.springframework.org/schema/util"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/aop/ http://www.springframework.org/schema/aop/spring-aop.xsd
                http://www.springframework.org/schema/context/ http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/jee/ http://www.springframework.org/schema/jee/spring-jee.xsd
                http://www.springframework.org/schema/lang/ http://www.springframework.org/schema/lang/spring-lang.xsd
                http://www.springframework.org/schema/tx/ http://www.springframework.org/schema/tx/spring-tx.xsd
                http://www.springframework.org/schema/util/ http://www.springframework.org/schema/util/spring-util.xsd">
            <context:annotation-config />(ERROR OCCUR)
            <context:component-scan base-package="hiberrSpring" /> (ERROR OCCUR)
            <bean id="jspViewResolver"
                class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView"></property>
                <property name="prefix" value="/WEB-INF/"></property>
                <property name="suffix" value=".jsp"></property>
            </bean>
            <bean id="messageSource"
                class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
                <property name="basename" value="classpath:messages"></property>
                <property name="defaultEncoding" value="UTF-8"></property>
            </bean>
            <bean id="propertyConfigurer"
                class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
                p:location="/WEB-INF/jdbc.properties"></bean>
            <bean id="dataSource"
                class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
                p:driverClassName="${com.mysql.jdbc.Driver}"
                p:url="${jdbc:mysql://localhost/}" p:username="${root}"
                p:password="${rajini}"></bean>
            <bean id="sessionFactory"
                class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                <property name="dataSource" ref="dataSource"></property>
                <property name="configLocation">
                    <value>classpath:hibernate.cfg.xml</value>
                </property>
                <property name="configurationClass">
                    <value>org.hibernate.cfg.AnnotationConfiguration</value>
                </property>
                <property name="hibernateProperties">
                    <props>
                        <prop key="hibernate.dialect">${org.hibernate.dialect.MySQLDialect}</prop>
                        <prop key="hibernate.show_sql">true</prop>
                    </props>
                </property>
            </bean>
            <bean id="employeeDAO" class="hiberrSpring.EmployeeDaoImpl"></bean>
            <bean id="employeeManager" class="hiberrSpring.EmployeeManagerImpl"></bean>
            <tx:annotation-driven /> (ERROR OCCUR)
            <bean id="transactionManager"
                class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                <property name="sessionFactory" ref="sessionFactory"></property>
            </bean>
        </beans>
    
    0 讨论(0)
  • 2020-11-29 09:49

    In my case this was actually a symptom of the server, hosted on AWS, lacking an IP for the external network. It would attempt to download namespaces from springframework.org and fail to make a connection.

    0 讨论(0)
提交回复
热议问题