这几天配置spring data jpa时,使用声明式事务碰到了一个奇怪的问题,无论怎么配置xml或在方法上使用@Transactional(value = "tm1")都会报如下找不到事务管理器的错误:
Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: tm2,tm1
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:370)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:271)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy20.save(Unknown Source)
at org.fxbird.springjpa.service.DepartmentServiceImpl.addDeptAndEmp(DepartmentServiceImpl.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy24.addDeptAndEmp(Unknown Source)
at org.fxbird.springjpa.App.main(App.java:15)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:365)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:370)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:271)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy20.save(Unknown Source)
at org.fxbird.springjpa.service.DepartmentServiceImpl.addDeptAndEmp(DepartmentServiceImpl.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy24.addDeptAndEmp(Unknown Source)
at org.fxbird.springjpa.App.main(App.java:15)
我的配置:
<?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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <aop:config> <aop:pointcut id="serviceOperation" expression="execution(* org.fxbird.springjpa.service.*ServiceImpl.*(..))"/> <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="tm1"> <tx:attributes> <tx:method name="find*" read-only="true"/> <tx:method name="count*" propagation="NEVER"/> <tx:method name="*" /> </tx:attributes> </tx:advice> <bean abstract="true" id="baseDS" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true"> <property name="initialSize" value="3"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean> <bean id="dataSource1" parent="baseDS"> <property name="url"> <value>jdbc:mysql://localhost/company?useUnicode=true&characterEncoding=utf-8</value> </property> </bean> <bean id="dataSource2" parent="baseDS"> <property name="url"> <value>jdbc:mysql://localhost/employee?useUnicode=true&characterEncoding=utf-8</value> </property> </bean> <bean abstract="true" id="baseEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="packagesToScan" value="org.fxbird.springjpa.model"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"/> </property> <property name="jpaProperties"> <props> <prop key="databasePlatform">org.eclipse.persistence.platform.database.MySQLPlatform</prop> <prop key="eclipselink.jdbc.cache-statements">true</prop> <prop key="eclipselink.weaving">false</prop> <prop key="eclipselink.logging.level">FINEST</prop> <prop key="eclipselink.allow-zero-id">true</prop> <!--<prop key="eclipselink.target-server">com.atomikos.eclipselink.platform.AtomikosTransactionController</prop>--> <!--<prop key="eclipselink.external-transaction-controller">true</prop>--> </props> </property> </bean> <bean id="emfCompany" parent="baseEmf"> <property name="dataSource" ref="dataSource1"/> </bean> <bean id="emfEmp" parent="baseEmf"> <property name="dataSource" ref="dataSource2"/> </bean> <bean id="tm1" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="emfCompany"/> </bean> <bean id="tm2" name="tm2" class="org.springframework.orm.jpa.JpaTransactionManager"> <qualifier value="tm2"/> <property name="entityManagerFactory" ref="emfEmp"/> </bean> <context:component-scan base-package="org.fxbird.springjpa.service" /> <jpa:repositories base-package="org.fxbird.springjpa.repo.company" entity-manager-factory-ref="emfCompany" transaction-manager-ref="tm1"/> <jpa:repositories base-package="org.fxbird.springjpa.repo.emp" entity-manager-factory-ref="emfEmp" transaction-manager-ref="tm2"/> <tx:annotation-driven /> </beans>
后来我找来了书上的例子,却一切正常,仔细对比了代码的不同好几遍,没发现任何异常,头发却快掉了好几十根了。第二天又试了一下,忽然怀疑是不是有可能jar包版本不同导致的,书上的例子用的是spring 4.0.2,而我用的是4.1.4,换成书上的版本一运行果然错误没了,shit,困扰我好几天了,又换成最新的4.1.6,也没有问题,看来就是版本问题了。
相关推荐
6. **事务管理**:Spring提供了声明式和编程式的事务管理,使得开发者能轻松地处理事务边界,确保数据的一致性。 7. **测试支持**:Spring提供了一系列的测试工具和框架,如`Spring Test`和`Spring Boot Test`,...
wdaaaaaaaaaafwawfw
scratch少儿编程逻辑思维游戏源码-十字鸭子.zip
Android移动应用开发_ViewFlow自定义控件CircleFlowIndicator指示器网络图片加载缓存自动循环滚动手势滑动交互_横向循环平滑滚动广告条Banne
前端开发_基于jQuery和EasyUI框架_企业级Web应用UI组件库与后台管理系统模板_提供GPL开源版本和商业授权版本的双重授权模式_适用于快速构建响应式管理后台和复杂数据可
《C++编程实例100篇》是一本深入实践、极具价值的编程教程,它针对C++编程语言提供了丰富的实例,旨在帮助读者更好地理解和掌握C++的各项特性与编程技巧。这本书的经典之处在于它将理论与实践相结合,通过100个精心设计的编程实例,覆盖了C++的各个核心领域,包括基础语法、面向对象编程、模板、异常处理、STL(标准模板库)等。 我们来探讨C++的基础语法。C++是C语言的增强版,它保留了C语言的高效性和灵活性,并引入了类、对象和继承等面向对象编程概念。基础语法包括变量声明、数据类型、运算符、控制结构(如if语句、for循环、while循环)、函数的定义和调用等。在实例中,你可能会遇到如何编写简单的程序,如计算两个数的和,或者实现一个简单的猜数字游戏。 C++的面向对象编程是其一大特色。通过类和对象,你可以构建复杂的软件系统。类是对象的蓝图,它定义了对象的属性和行为。实例化一个类,就是创建一个具体的对象。继承允许你创建新的类,这些类从现有的类派生,共享其属性和方法,同时可以添加新的功能。多态性是面向对象的另一个关键特性,它使得不同类型的对象可以对同一消息作出不同的响应。这些概念在实例中会以各种形式展现,例如设计一个图形界面的类层次,或实现一个简单的模拟游戏。 接下来是模板,C++的模板功能让代码更加通用,可以处理不同类型的数据。模板分为函数模板和类模板,前者可以创建泛型函数,后者可以创建泛型类。通过模板,你可以编写出高效且灵活的代码,比如实现一个通用的排序算法。 异常处理是C++中用于处理程序运行时错误的机制。当程序出现异常情况时,可以抛出一个异常,然后在适当的点捕获并处理这个异常。这使得代码能够优雅地处理错误,而不是让程序崩溃。实例中可能会有涉及文件操作或网络通信时可能出现的异常处理示例。
scratch少儿编程逻辑思维游戏源码-忍者无限跑者.zip
少儿编程scratch项目源代码文件案例素材-战斗机游戏.zip
手工DIY行业_微信小程序云开发_手工坊预约管理系统_基于腾讯云开发技术的手工DIY行业线上线下结合解决方案_包含手工项目展示预约管理签到核销数据统计等完整功能_支持后台时段设置人
内容概要:本文档汇总了FFmpeg工具的多个实用命令示例,涵盖音频和视频处理的各个方面。包括但不限于:音频采样率转换、音频格式转为raw、查询音频文件时长与音量检测、调整音频音量大小、改变音频播放速度、视频逆序播放(针对无音频视频)、精准视频片段截取、音频片段截取、视频与音频合并处理、调整视频宽高比等。每个命令都提供了具体的参数设置方法; 适合人群:音视频编辑爱好者、多媒体处理领域的初学者或有一定经验的技术人员; 使用场景及目标:①在音频处理方面,可以完成从格式转换到音质调整的任务;②在视频处理上,能够实现基本的剪辑操作如切割、翻转、合并等;③为用户提供了一站式的解决方案,帮助用户快速掌握FFmpeg命令行工具的基本用法,提高工作效率; 阅读建议:本指南以命令实例为主,建议读者结合实际需求选择相应的命令进行尝试,在实践中理解各个参数的作用并灵活运用。
一、毕业设计的技术背景和设计依据 计算机硬盘驱动器作为一种存储数据信息的设备,在目前的计算机系统中起着不可替代的作用,读写的快慢对整个计算机系统的性能无疑占有重要地位。硬盘式电子计算机磁记录机构中最为精密的一类微机电系统设备,它对振动的敏感性是由其结构决定的,而其控制尚未很好的解决,针对硬盘展开建模及控制有着重要的实际应用价值。 二、毕业设计的任务 现代硬盘一般有 1 - 5 个盘片,以常见的 3.5 英寸硬盘为例,盘片直径约为 95mm,厚度约为 0.635mm。磁头数量通常与盘片数量相关,每面盘片有一个磁头,比如一个 3 盘片的硬盘就有 6 个磁头。缓存大小可能为 32MB、64MB 或 128MB 等,如某普通硬盘缓存为 64MB,电机功率一般在 2 - 5W,像转速为 7200RPM(转每分钟)的电机功率约 3W。数据写入时,磁头在电机带动下,以平均寻道速度约 10 - 15m/s 定位磁道。以一块顺序写入数据的硬盘为例,当写入连续大文件,如 1GB 的视频文件时,在 SATA3.0 接口下,理论传输带宽为 6Gb/s(约 750MB/s),实际可达 500 - 600MB/s。读取时,磁头感应盘片磁场变化,如读取小文件(1MB 大小),若磁头寻道距离平均为 1000 个磁道,每次寻道时间约 8 - 12ms,读取速度会因寻道而下降到 10 - 20MB/s。 本设计选取硬盘驱动器作为研究对象,假设电机扭矩为 0.3N・m,盘片转动惯量为 0.003kg・m²,轴承摩擦力矩为 0.03N・m。在稳定旋转阶段,转速波动范围设为额定转速的 ±0.5%,即 ±36RPM。首先通过对该系统分析建立了其物理模型,然后针对以音圈电机作为伺服机构的硬盘磁头定位伺服系统的性能要求,对音圈电机的控制设计采用三种控制器方案,即极点配置法、PID控制方法、线性二次型调节器方法,分别比较分
scratch少儿编程逻辑思维游戏源码-猫猫冲刺.zip
大数据处理_全文搜索引擎_ElasticSearch中文发行版_基于最新稳定版ElasticSearch预集成中文分词插件及常用配置的开箱即用解决方案_专为中文开发者优化的免配置高
离散数学_逻辑演算系统_真值表生成器_主范式计算器_最简范式求解器_王浩算法实现_等值演算工具_命题逻辑分析平台_基于Web的交互式逻辑运算系统_用于离散数学教学与研究的综合性逻辑
商业智能_SpringBoot_MQ_AIGC_React_智能数据分析_可视化图表_自动分析_数据集处理_用户诉求解析_数据降本增效_基于人工智能的商业智能分析平台_通过自然语言
少儿编程scratch项目源代码文件案例素材-爪猫小车.zip
少儿编程scratch项目源代码文件案例素材-拽猫挥剑.zip
kuishou68_neteaseMusic_32152_1745866029873
少儿编程scratch项目源代码文件案例素材-种族叛徒.zip
scratch少儿编程逻辑思维游戏源码-色彩交换.zip