org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: txManager,batchtxManager 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.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.$Proxy77.sendAmqpPacket1(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
1
sodadev OP 大概意思是扫描到两个 org.springframework.transaction.PlatformTransactionManager 类型的 bean 是这个意思吗
|
2
manr 2019-06-26 11:03:47 +08:00
expected single matching bean but found 2: txManager,batchtxManager
重复扫描了吧,看看这两个 bean 配置 |
3
airfling 2019-06-26 11:05:49 +08:00
你要去除 hibernate 的事务配置,或者去除 batch 的事务配置就可以了
|
4
sodadev OP <!-- spring batch 配置开始 -->
<bean id="batchtxManager" lazy-init="true" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean" p:dataSource-ref="dataSource"><!-- 用于查询所有 job 实例 --> </bean> <batch:job-repository id="jobRepository" data-source="dataSource" transaction-manager="batchtxManager" isolation-level-for-create="SERIALIZABLE" table-prefix="BATCH_" /> <task:executor id="executor"></task:executor><!-- 异步 --> <bean id="jobLauncherAsyn" class="com.javaoa.batch.launcher.CustmJobLauncher"><!-- class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> --> <property name="jobRepository" ref="jobRepository" /> <property name="taskExecutor" ref="executor"></property> </bean> <batch:job id="restartSynchronizedJob" restartable="true"> <batch:step id="restartSynchronizedStep" > <batch:tasklet transaction-manager="txManager"> <batch:chunk reader="itemReader" writer="itemWriter" commit-interval="1" retry-policy="alwaysRetryPolicy"> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <bean id="alwaysRetryPolicy" class="org.springframework.retry.policy.AlwaysRetryPolicy" /> <bean id="itemReader" class="com.javaoa.batch.read.CustmGwjhItemRead" scope="step"> <property name="sessionFactory" ref="sessionFactory" /> <property name="sendUuid" value="#{jobParameters['sUuid']}"/> <property name="inceptId" value="#{jobParameters['inceptId']}"/> <property name="replyId" value="#{jobParameters['rpId']}"/> <property name="bmId" value="#{jobParameters['bmUuid']}"/> <property name="inceptDeptIds" value="#{jobParameters['inceptDeptIds']}"/> <property name="sendType" value="#{jobParameters['type']}"/> <property name="hqYeWuUuid" value="#{jobParameters['hqYWUuid']}"/> <property name="hqDwUuid" value="#{jobParameters['hqDanweiUuid']}"/> <property name="proccessInst" value="#{jobParameters['proccessInstUuid']}"/> <property name="activityInstId" value="#{jobParameters['activityInstId']}"/> <property name="jblUuid" value="#{jobParameters['jblUuid']}"/> <!-- <property name="delegate" ref="hibernateCursorReader"/> --> </bean> <bean id="itemWriter" class="com.javaoa.batch.writer.CustmWriter" scope="step"> <property name="sessionFactory" ref="sessionFactory" /> <property name="sendUuid" value="#{jobParameters['sUuid']}"/> <property name="inceptId" value="#{jobParameters['inceptId']}"/> <property name="sendType" value="#{jobParameters['type']}"/> <property name="hqYeWuUuid" value="#{jobParameters['hqYWUuid']}"/> <property name="hqDwUuid" value="#{jobParameters['hqDanweiUuid']}"/> <property name="proccessInst" value="#{jobParameters['proccessInstUuid']}"/> <property name="activityInstId" value="#{jobParameters['activityInstId']}"/> <property name="jblUuid" value="#{jobParameters['jblUuid']}"/> </bean> <!-- spring batch 配置结束 --> |
5
sodadev OP <!-- 开启注解事务 只对当前配置文件有效 -->
<tx:annotation-driven transaction-manager="txManager"/> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> <property name="globalRollbackOnParticipationFailure" value="false" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="create*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="merge*" propagation="REQUIRED" /> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="put*" propagation="REQUIRED" /> <tx:method name="use*" propagation="REQUIRED"/> <!--hibernate4 必须配置为开启事务 否则 getCurrentSession()获取不到--> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="count*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> |
8
limuyan44 2019-06-26 11:40:46 +08:00 via Android
去掉一个不就好了,怎么可能不配置事务 Tomcat 就报错的,不行你试试 springbatch 的配置用 txmanager
|