spring cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素'tx:annotation-driven'的声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17566391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 06:04:18  来源:igfitidea点击:

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

springspring-mvc

提问by osh

If i do not paste xmlns:tx="http://www.springframework.org/schema/tx"then there are no problems. However if i do insert the text i get an cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven' error.

如果我不粘贴 xmlns:tx="http://www.springframework.org/schema/tx",则没有问题。但是,如果我确实插入了文本,我会得到一个 cvc-complex-type.2.4.c:匹配的通配符是严格的,但是找不到元素“tx:annotation-driven”错误的声明。

<beans xmlns:tx="http://www.springframework.org/schema/tx" 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:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

    <context:annotation-config />
    <tx:annotation-driven /> 
<context:component-scan base-package="ne.projl.server" />

    <bean name="security.securityInfo" class="org.geomajas.security.SecurityInfo">
        <property name="loopAllServices" value="false" />
        <property name="securityServices">
            <list>
                <bean class="org.geomajas.security.allowall.AllowAllSecurityService" />
            </list>
        </property>
    </bean>

    <bean name="puregwt-app" class="org.geomajas.configuration.client.ClientApplicationInfo">
        <property name="maps">
            <list>
                <ref bean="mapOsm" />
<!--                <ref bean="mapWms" /> -->
<!--                <ref bean="mapLegend" /> -->
<!--                <ref bean="mapLayerVisibility" /> -->
<!--                <ref bean="mapCountries" /> -->
<!--                <ref bean="mapEmpty" /> -->
<!--                <ref bean="mapPrinting" /> -->
            </list>
        </property>
    </bean>
<bean class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" id="entityManagerFactory">
        <property name="persistenceUnitName" value="MyPUnit" />
    </bean>

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

I have also tried to modify <tx:annotation-driven />like so : <tx:annotation-driven transaction-manager="transactionManager"/>

我也尝试<tx:annotation-driven />像这样修改:<tx:annotation-driven transaction-manager="transactionManager"/>

回答by Kevin Bowersox

The schema location for tx is never provided in the <beans>tag. Notice the change in the last line of the provided configuration. Also the config mixes Spring 2.0 with 2.5, I'm not sure if this is desired, but I wanted to make you aware this.

<beans>标签中从未提供 tx 的架构位置。请注意所提供配置的最后一行的更改。此外,配置混合了 Spring 2.0 和 2.5,我不确定这是否需要,但我想让您意识到这一点。

<beans xmlns:tx="http://www.springframework.org/schema/tx" 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:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

回答by srinivas

I need to swap the line content to remove the error--

我需要交换行内容以消除错误--

http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/context

Just an interchange solved my error -- as below

只是一个交换解决了我的错误 - 如下

http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd

回答by Mightian

I was able to solve this issue by adding these 2 declarations inside the xsi:schemaLocation. http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
add the above it worked for me

我能够通过在 xsi:schemaLocation 中添加这 2 个声明来解决这个问题。 http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
添加上面对我有用的内容

回答by Master Mind

This is worked for me with Spring 3.X+ Hibernate+MySQL+ Maven

这适用于 Spring 3.X+ Hibernate+MySQL+ Maven

servlet-context.xml

servlet-context.xml

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

    <!-- 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="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:annotation-config />



    <beans:bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <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:property name="packagesToScan" value="com.hb.test.modal" />
    </beans:bean>


    <beans:bean id="dataSource" name="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <beans:property name="url"
            value="jdbc:mysql://localhost:3306/mydb" />
        <beans:property name="username" value="root" />
        <beans:property name="password" value="root" />
    </beans:bean>
    <beans:bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="sessionFactory" />
    </beans:bean>
    <tx:annotation-driven transaction-manager="transactionManager" />
    <context:component-scan base-package="com.hb.test" />

</beans:beans>

pom.xml

pom.xml

    <!--Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.0.Final</version>
    </dependency>

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.32</version>
    </dependency>
    <!-- AOP dependency -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>

    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>

回答by ZhaoGang

When we deal with errors in a xml file, we should notice that, there are bugs for eclipse, and if we cut the errored line, and then paste it back again, the errors may disappear as a magic. I have hit this eclipse bug several times.

当我们处理xml文件中的错误时,我们应该注意到,eclipse存在错误,如果我们将错误的行剪掉,然后再粘贴回去,错误可能会像魔术一样消失。我已经多次遇到这个日食错误。