天天看點

Spring報nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in point

在我們使用spring注解方式寫通知時,例如
@AfterReturning(value = "pointcut()")
    public void after(JoinPoint jp,Object returningValue){
        System.out.println("注解方式實作【後置通知】"+
                jp.getSignature().getName()+"目标對象:"+
                jp.getTarget()+","+"參數的傳回值:"+returningValue);
    }
           

Object returningValue是後置通知直接 得到傳回值,這個使用時是特别的友善,但是用這樣的方式做業務會報:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘studentDaoImpl’ defined in class path resource [applicationContext.xml]: 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:553)

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

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

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

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

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

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

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

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

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

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

我們的解決方式為:

Spring報nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in point

在方法中聲明一下就可以了:

Spring報nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in point