spring aop出错: Caused by: java.lang.IllegalArgumentException: error Type referred to is not an annotation type: com.aop.ServiceErrorAop
原创    ren_xian    发表于:2018-07-12 10:08:13
  阅读 :82   收藏   编辑

使用spring aop拦截某一注解,启动出错:

Caused by: java.lang.IllegalArgumentException: error Type referred to is not an annotation type: com.dmd.aop.ServiceErrorAop
	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:301)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)
	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:280)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
	at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:346)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:298)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
	... 42 more

解决办法:

在aop中的参数的要统一,如下,保证@annotation(err)中的err与方法参数中保持一致

@AfterThrowing(value="@annotation(err)",throwing="e")
	public void doAfterThrowing(JoinPoint joinPoint,ServiceErrorAnnotation err,Throwable e) {
		try {
			...
			
		}catch (Exception e1) {
			e1.printStackTrace();
		}
	}

参考:https://stackoverflow.com/questions/36789966/spring-aop-error-error-type-referred-to-is-not-an-annotation-type

评论
条评论