Cannot resolve reference to bean ‘transactionManager‘ while setting bean property ‘transactionManage

**

Error creating bean with name ‘txadvice’: Cannot resolve reference to bean ‘transactionManager’ while setting bean property ‘transactionManager’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘transactionManager’ available

**

基于XML文件的配置产生异常环境

**
spring配置声明式事务产生异常

异常描述

ERROR StatusLogger No Log4j 2 configuration file found. Using
              default configuration (logging only errors to the console), or
              user programmatically provided configurations. Set system
              property 'log4j2.debug' to show Log4j 2 internal initialization
              logging. See
              https://logging.apache.org/log4j/2.x/manual/configuration.html
              for instructions on how to configure Log4j 2 二月 28, 2021 10:57:24
              下午 org.springframework.context.support.AbstractApplicationContext
              refresh 警告: Exception encountered during context initialization -
              cancelling refresh attempt:
              org.springframework.beans.factory.BeanCreationException: Error
              creating bean with name 'userService' defined in file [D:\Program
              Files\Spring5_txDemo1\out\production\Spring5_txDemo1\com\service\UserService.class]:
              Initialization of bean failed; nested exception is
              org.springframework.beans.factory.BeanCreationException: Error
              creating bean with name 'txadvice': Cannot resolve reference to
              bean 'transactionManager' while setting bean property
              'transactionManager'; nested exception is
              org.springframework.beans.factory.NoSuchBeanDefinitionException:
              No bean named 'transactionManager' available
              
              org.springframework.beans.factory.BeanCreationException: Error
              creating bean with name 'userService' defined in file [D:\Program
              Files\Spring5_txDemo1\out\production\Spring5_txDemo1\com\service\UserService.class]:
              Initialization of bean failed; nested exception is
              org.springframework.beans.factory.BeanCreationException: Error
              creating bean with name 'txadvice': Cannot resolve reference to
              bean 'transactionManager' while setting bean property
              'transactionManager'; nested exception is
              org.springframework.beans.factory.NoSuchBeanDefinitionException:
              No bean named 'transactionManager' available
              
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
              	at
              org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
              	at
              org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
              	at
              org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
              	at
              org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
              	at
              org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
              	at
              org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
              	at com.test.UserTest.test2(UserTest.java:21) 	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
              	at
              org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
              	at
              org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
              	at
              org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
              	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
              	at
              org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
              	at
              org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
              	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
              	at
              org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
              	at
              org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
              	at
              org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
              	at
              org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
              	at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 	at
              org.junit.runner.JUnitCore.run(JUnitCore.java:137) 	at
              com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
              	at
              com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
              	at
              com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
              	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
              Caused by:
              org.springframework.beans.factory.BeanCreationException: Error
              creating bean with name 'txadvice': Cannot resolve reference to
              bean 'transactionManager' while setting bean property
              'transactionManager'; nested exception is
              org.springframework.beans.factory.NoSuchBeanDefinitionException:
              No bean named 'transactionManager' available 	at
              org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:342)
              	at
              org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:113)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1699)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1444)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
              	at
              org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)
              	at
              org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor.getAdvice(AbstractBeanFactoryPointcutAdvisor.java:116)
              	at
              org.springframework.aop.aspectj.AspectJProxyUtils.isAspectJAdvice(AspectJProxyUtils.java:71)
              	at
              org.springframework.aop.aspectj.AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(AspectJProxyUtils.java:52)
              	at
              org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.extendAdvisors(AspectJAwareAdvisorAutoProxyCreator.java:95)
              	at
              org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:96)
              	at
              org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:76)
              	at
              org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:347)
              	at
              org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
              	at
              org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
              	... 33 more Caused by:
              org.springframework.beans.factory.NoSuchBeanDefinitionException:
              No bean named 'transactionManager' available 	at
              org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:814)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1282)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
              	at
              org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
              	at
              org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:330)
              	... 53 more
              
              
              Process finished with exit code -1 ```
             

异常产生原因:

配置声明式事务时,将bean 标签的 id属性取值没有取transactionManager而是随意取的。
在这里插入图片描述解决方法:

将配置声明书事务的bean标签id取值改成transactionManager即可

在这里插入图片描述总结:
id里的dataSourceTransactionManager一定要记得不要乱写,并且一定要记得小写,切勿写成TransactionManager
血的教训,找了我几个小时,来来回回各种改!

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页