spring aop 报错:Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

  刚把上一个aop bug解决了,继续下一步,又出错了,调了一天的bug,不过收获还是很大的,对spring aop有了更深的了解!

  这次出的错误代码如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in file [E:\eclipse\workspace\maven\target\classes\com\bjsd\aop\service\impl\UserServiceImpl.class]: 
  Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:296)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
	at com.bjsd.test.aoptest.Test(aoptest.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
	at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:319)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:206)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:192)
	at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:169)
	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:208)
	at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
	at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
	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:376)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:339)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1558)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
	... 31 more
    百度告诉我说这是 在使用注解配置spring aop advice(通知)时参数配置错误;

   出错的代码如下:

/**
 * 定义一个Transaction切面类 测试after,before,around,throwing,returning Advice.
 * 
 * @author you
 * 
 *         TODO
 */
@Aspect
// 声明该类是切面类
@Component
// 配置文件中启动自动扫描功能,将该切面交给spring 去管理
public class Transaction {

  private transient static Logger logger = LoggerFactory.getLogger(Transaction.class);
  // 定义切点
  @Pointcut("execution(* com.bjsd.aop.service.*.*(..))")
  public void allMethod() {
   };
/**
   * 核心业务逻辑调用正常退出后,不管是否有返回值,正常退出后,均执行此Advice
   * 
   * 
   * 
   * @param joinPoint
   */
   @AfterReturning("allMethod()")
   private void doReturn(JoinPoint joinPoint) {
   System.out.println("-----doReturn().invoke-----");
   System.out.println(" 此处可以对返回值做进一步处理");
   System.out.println(" 可通过joinPoint来获取所需要的内容");
   System.out.println("-----End of doReturn()------");
   }

  /**
   * 核心业务逻辑调用异常退出后,执行此Advice,处理错误信息
   * 
   * @param joinPoint
   * @param ex
   */
   @AfterThrowing("allMethod()")
   private void doThrowing(JoinPoint joinPoint, Throwable ex) {
   System.out.println("-----doThrowing().invoke-----");
   System.out.println(" 错误信息:" + ex.getMessage());
   System.out.println(" 此处意在执行核心业务逻辑出错时,捕获异常,并可做一些日志记录操作等等");
   System.out.println(" 可通过joinPoint来获取所需要的内容");
   System.out.println("-----End of doThrowing()------");
   }
}
   错误的愿意是:注解@AfterReturning和@AfterThrowing对应spring aop advice(通知)中都有一个形式参数,这个形式参数对应的是目标方法执行结束后返回的参数;所以还要配置这两个通知的参数;

 修改后的代码如下:

  /**
   * 核心业务逻辑调用正常退出后,不管是否有返回值,正常退出后,均执行此Advice
   * 
   * 
   * 
   * @param joinPoint
   */
   @AfterReturning(value = "allMethod()", returning = "result")
   private void doReturn(JoinPoint joinPoint, Object result) {
   System.out.println("-----doReturn().invoke-----");
   System.out.println(" 此处可以对返回值做进一步处理");
   System.out.println("输出的返回值为+" + result);
   System.out.println(" 可通过joinPoint来获取所需要的内容");
   System.out.println("-----End of doReturn()------");
   }

  /**
   * 核心业务逻辑调用异常退出后,执行此Advice,处理错误信息
   * 
   * @param joinPoint
   * @param ex
   */
   @AfterThrowing(value = "allMethod()", throwing = "ex")
   private void doThrowing(JoinPoint joinPoint, Throwable ex) {
   System.out.println("-----doThrowing().invoke-----");
   System.out.println(" 错误信息:" + ex.getMessage());
   System.out.println(" 此处意在执行核心业务逻辑出错时,捕获异常,并可做一些日志记录操作等等");
   System.out.println(" 可通过joinPoint来获取所需要的内容");
   System.out.println("-----End of doThrowing()------");
   }
  也写完博客了也下班了,走喽!朋友们有啥见解请留言!


©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页