当前位置: 首页 > 知识库问答 >
问题:

Spring“元素“tx:注释驱动”的前缀“tx”未绑定。”

凌声
2023-03-14

我在我的“tx:注解驱动”行上得到了上面的错误,但是我已经在bean文件的顶部声明了命名空间,为什么以下XML会导致这个错误?

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

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

    <!-- Enables the Spring MVC @Controller programming model -->
    <tx:annotation-driven transaction-manager="hibernateTransactionManager"/>

    <!-- 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>

    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <beans:property name="url" value="jdbc:mysql://localhost/assessme" />
        <beans:property name="username" value="assessme" />
        <beans:property name="password" value="assessme" />
    </beans:bean>

     <beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <beans:property name="annotatedClasses">
        <beans:list>
            <beans:value>org.assessme.com.entity.User</beans:value>
        </beans:list>
    </beans:property>
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="packagesToScan" value="org.assessme.com.controller.entity" />
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</beans:prop>
                <beans:prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
                <beans:prop key="hibernate.hbm2ddl.auto">update</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>

    <context:component-scan base-package="org.assessme.com." />

    <beans:bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <beans:property name="mediaTypes">
            <beans:map>
                <beans:entry key="html" value="text/html" />
                <beans:entry key="json" value="application/json" />
            </beans:map>
        </beans:property>
        <beans:property name="defaultViews">
            <beans:list>
                <beans:bean
                    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
                    <beans:property name="prefixJson" value="true" />
                </beans:bean>
            </beans:list>
        </beans:property>
    </beans:bean>
<beans:bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="sessionFactory" />
    </beans:bean>

</beans:beans>

共有3个答案

戚飞虎
2023-03-14

您必须将注释引入您的项目,您必须安装它们,不要使用xmlns,它不能正常工作,我看到您使用注释进行开发,它的良好实践和使用它,

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd

岳志义
2023-03-14

您可以在这里查看更多信息:

tx标记处理在Spring的事务综合支持中配置所有这些bean。标题为第9章交易管理的章节介绍了这些标签。

...

为了完整性,要在tx模式中使用标记,您需要在Spring-XML配置文件的顶部有以下序言;以下代码段中的加粗文本引用了正确的模式,因此您可以使用tx命名空间中的标记。

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

   <!-- <bean> definitions goes here -->

</beans>
姜森
2023-03-14

就像您的其他xmlns:定义一样,您需要一个xmlns: tx

xmlns:tx="http://www.springframework.org/schema/tx"
 类似资料:
  • 问题内容: 我在“ tx:annotation-driven”行上收到上述错误,但是我在Bean文件的顶部声明了名称空间,为什么以下XML导致此错误? 问题答案: 就像其他xmlns:定义一样,您需要一个xmlns:tx

  • 我在“tx:annotation-driven”行中得到了上面的错误,但是我已经在bean文件的顶部声明了命名空间,为什么下面的XML会导致这个错误?

  • 你好,朋友,我正在开发基于spring(4.0.3)和hibernate(4.3.6)的应用程序。在会话工厂中保存任何对象时,我遇到以下错误: 下面是我在application-context.xml中使用的条目 还有一件事我想带到这里,如果我在事务管理器属性中使用了任何值,而不是实际的transactionManager作为bean引用,那么这不是抛出错误。所以我认为它没有参考价值<请帮帮我!!

  • 当我评论tx:annotation-drive时,一切都很好,但是带有@transactional注释的method不起作用。我做错了什么? 我的年级依赖关系:

  • 主要内容:1.@Transactional 失败的情况,2.@Transactional 源码分析,3.@Transactional 失效原因1.@Transactional 失败的情况 UserDao UserController @Transactional 事务不生效的几种情况 类内部访问:A 类的 a1 方法没有标注 @Transactional,a2 方法标注 @Transactional,在 a1 里面调用 a2; 私有方法:将 @Transactional 注解标注在非 publi

  • LCN分布式事务 "LCN并不生产事务,LCN只是本地事务的搬运工" 框架介绍 LCN分布式事务框架是一款事务协调性的框架,框架本身并不创建事务,只是对本地事务做协调控制。因此该框架与其他第三方的框架兼容性强,支持所有的关系型数据库事务,支持多数据源,支持与第三方数据库框架一块使用(例如 sharding-jdbc),在使用框架的时候只需要添加分布式事务的注解即可,对业务的侵入性低。LCN框架主要