博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring事务管理配置以及异常处理
阅读量:6567 次
发布时间:2019-06-24

本文共 13530 字,大约阅读时间需要 45 分钟。

Spring事务管理配置:

遇到这样的异常:

 

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring/ApplicationContext.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Ljava/lang/Object;)V    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:413)    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1863)    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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618)    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565)    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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)    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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)    at sun.rmi.transport.Transport$1.run(Transport.java:200)    at sun.rmi.transport.Transport$1.run(Transport.java:197)    at java.security.AccessController.doPrivileged(Native Method)    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)    at java.security.AccessController.doPrivileged(Native Method)    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)    at java.lang.Thread.run(Thread.java:748)Caused by: java.lang.NoSuchMethodError: org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Ljava/lang/Object;)V    at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parseInternal(AnnotationDrivenBeanDefinitionParser.java:54)    at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:60)    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1424)    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1414)    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:141)    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)    ... 58 more 一月 22, 2018 11:28:39 上午 org.apache.catalina.core.ApplicationContext log信息: Closing Spring root WebApplicationContext一月 22, 2018 11:28:39 上午 org.apache.catalina.core.StandardContext listenerStop严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListenerjava.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:921)    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:895)    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841)    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115)    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5165)    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5829)    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:221)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:149)    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1863)    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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:618)    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:565)    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.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)    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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)    at sun.rmi.transport.Transport$1.run(Transport.java:200)    at sun.rmi.transport.Transport$1.run(Transport.java:197)    at java.security.AccessController.doPrivileged(Native Method)    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)    at java.security.AccessController.doPrivileged(Native Method)    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)    at java.lang.Thread.run(Thread.java:748)

 

我一直以为配置事务管理xml什么地方配置出错了,后来说解释,该问题因为

org.springframework
spring-dao
2.0.8

Spring4不需要导入该架包,因为spring-dao已经被spring-tx所取代,参见Spring有关Spring 2.0和2.5中的新特性的文档。第2.7.1.2节。jar包装在spring2.5。您会注意到,spring-tx api和spring-dao api都包含AopNamespaceUtils类,并且重载了registerAutoProxyCreatorIfNecessary方法。然而,只有在[spring-dao api中,类有一个接受一个对象的版本作为第二个参数。这个调用正在被Spring的反射性地作为Spring-dao中存在的第二个参数寻找一个方法的期望。然而,spring-tx类被拿起来,并没有一个Object作为第二个参数的方法,因此你会得到上面面的异常。

 

 

解决方式:

删除Spring-dao依赖。

 

转载于:https://www.cnblogs.com/weixupeng/p/10706413.html

你可能感兴趣的文章
Lync2013 恢复-整残之后如何重新安装
查看>>
SSO 单点登录会话管理
查看>>
jpa查询记录重复
查看>>
mysql-事物实现原理
查看>>
上下滚动播报特效
查看>>
iOS 隐藏导航栏整个视图上移闪屏问题
查看>>
12cR2 RAC+RAC+ADG ORA-16854
查看>>
数组名和数组名取地址的区别
查看>>
某企业WSUS服务实例介绍
查看>>
准IT工作者如何择师、如何学习
查看>>
redis主从复制故障转移
查看>>
2011,我的IT我的梦
查看>>
KVM虚拟化实践(一)
查看>>
First Unique Character in a String(leetcode387)
查看>>
计算机体系架构简析
查看>>
另类无法在ESXi上添加存储器故障
查看>>
select 下拉菜单Option对象使用add(elements,index)方法动态添加
查看>>
tomcat及负载均衡
查看>>
Linux磁盘管理(实验)
查看>>
【XXX贷】2014年10月XX日发标预告
查看>>