spring aop报错

最近没事,看了下spring的aop什么的,想在项目中作个记录错误日志的这样的一个东西熟悉一下aop,结果报错,求高手指导啊,谢谢:
applicationContext.xml中aop的相关配置:
<bean id="myAspect" class="com.demo.util.ExceptionAspect"/>
 <aop:config>
  <aop:pointcut id="servicePointcut" expression="execution(* com.demo.action.* (..))"/>

  <aop:aspect ref="myAspect">
   <aop:after-throwing pointcut-ref="servicePointcut" method="writerException" throwing="ex"/>
  </aop:aspect>
 </aop:config>

 

启动报错,不要这段是可以正常运行的,错误信息如下 :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: com.demo.action [Xlint:invalidAbsoluteTypeName]
 at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
 at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
 at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
 at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
 at java.util.concurrent.FutureTask.run(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: warning no match for this type name: com.demo.action [Xlint:invalidAbsoluteTypeName]
 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
 at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)
 ... 25 more
Caused by: java.lang.IllegalArgumentException: warning no match for this type name: com.demo.action [Xlint:invalidAbsoluteTypeName]
 at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:302)
 at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:206)
 at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
 at org.springframework.aop.aspectj.AspectJExpressionPointcut.getMethodMatcher(AspectJExpressionPointcut.java:179)
 at org.springframework.aop.aspectj.AbstractAspectJAdvice.buildSafePointcut(AbstractAspectJAdvice.java:189)
 at org.springframework.aop.aspectj.AspectJPointcutAdvisor.<init>(AspectJPointcutAdvisor.java:51)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
 ... 27 more

 

把expression="execution(* com.demo.action.* (..))"换成expression="execution(* com.demo.action.*.* (..))"启动正常,访问的时候报错,错误信息如下:

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
 at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
 at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
 at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
 at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
 at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
 at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
 at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
 at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
 at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
 at org.springframework.aop.framework.Cglib2AopProxy.createEnhancer(Cglib2AopProxy.java:229)
 at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:171)
 at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:490)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:365)
 at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:325)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)
 at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:172)
 at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:144)
 at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
 at com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
 at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
 at com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
 at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
 at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
 at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
 at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
 at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
 at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

 

ExceptionAspect.java内容如下:

package com.demo.util;

import java.util.Date;

public class ExceptionAspect {

 /**
  *  记录异常信息
  * @param ex  捕获到的异常
  */
 public void writerException(Exception ex){
  try {
   String msg="异常类型:"+ex.getMessage()+" 时间:"+new Date();
   FileUtil.writer("d://log.txt",true, msg);
   FileUtil.writer("d://log.txt", true, ex.toString());
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

 

1个回答

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(I)V
at net.sf.cglib.core.DebuggingClassWriter.(DebuggingClassWriter.java:47)
at

说明 asm jar包有冲突。检查classpath的asm相关jar包

yuan_bin1990
yuan_bin1990 谢谢老师啊,我把cglib-2.2.jar换成cglib-2.1.jar就好了,看了你写的《跟我学spring3》收获蛮多的,期待您的更多作品。
接近 8 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问