欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

aspectJ error at ::0 formal unbound in pointcut

程序员文章站 2022-06-16 17:32:28
...

 

 

异常详情

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'StudentsImpl' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception isjava.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)

   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)

   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)

   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)

   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)

   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)

   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

   at TestStudentsDAOProxy.main(TestStudentsDAOProxy.java:11)

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

   at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:302)

   at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:195)

   at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:181)

   at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:162)

   at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:200)

   at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:254)

   at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:286)

   at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117)

   at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)

   at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)

   at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)

   at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)

   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)

   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1426)

   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)

   ... 11 more

 

错误代码

package com.eden.proxy;

 

import java.lang.reflect.Method;

 

import org.aspectj.lang.annotation.AfterReturning;

import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Before;

import org.springframework.stereotype.Component;

 

/**

 * 使用AspectJ的切面类

 * @author Administrator

 */

@Aspect    //声明为一个 AspectJ切面

@Component//声明为组件,这样系统启动会进行该类的初始化

publicclass StudentsDaoAspectJ {

  

  

   @AfterReturning("execution(public void com.eden.dao.impl.StudentsImpl.*())")

   publicvoid afterReturning(Object arg0, Method arg1, Object[] arg2,

        Object arg3)throws Throwable {

      System.out.println("方法执行后。。。");

   }

   @Before("execution(public void com.eden.dao.impl.StudentsImpl.*())")

   publicvoid before(Method arg0, Object[] arg1, Object arg2)

        throws Throwable {

      System.out.println("方法执行前。。。");

   }

}

 

错误原因

      定义了通知方法,方法需要参数,但是注解设置没有指定调用方法参数,需要把通知方法中的参数删掉,变成空参数方法(如何设置带有参数的通知方法,还不清楚^_^

正确代码

package com.eden.proxy;

 

import java.lang.reflect.Method;

 

import org.aspectj.lang.annotation.AfterReturning;

import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Before;

import org.springframework.stereotype.Component;

 

/**

 * 使用AspectJ的切面类

 * @author Administrator

 */

@Aspect    //声明为一个 AspectJ切面

@Component//声明为组件,这样系统启动会进行该类的初始化

publicclass StudentsDaoAspectJ {

  

  

   @AfterReturning("execution(public void com.eden.dao.impl.StudentsImpl.*())")

   publicvoid afterReturning() throws Throwable {

      System.out.println("方法执行后。。。");

   }

   @Before("execution(public void com.eden.dao.impl.StudentsImpl.*())")

   publicvoid before()

        throws Throwable {

      System.out.println("方法执行前。。。");

   }

}

 

正确输出

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).

log4j:WARN Please initialize the log4j system properly.

方法执行前。。。

保存成功

方法执行后。。。