Showing posts with label aop. Show all posts
Showing posts with label aop. Show all posts

Wednesday, March 25, 2020

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



Error Blog 

Hi Guys ,
This blog is about the error    java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

Problem Statement

unable to start a spring boot application on using annotation based aspect .


Error Details 

error Log

ERROR DETAILS 
Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut 
at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:319) ~[aspectjweaver-1.9.5.jar:na]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:227) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:198) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:177) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:226) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:289) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:321) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:126) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:95) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:76) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:347) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) ~[spring-aop-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
... 25 common frames omitted



Error Code 

Please check the aspect class

  
   
package com.example.aop;
import org.aspectj.lang.JoinPoint;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Configurable;import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.slf4j.Logger;import org.springframework.stereotype.Component;
@Component@Aspectpublic class MyAspect {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyAspect.class);

    @Before("execution(* com.example.aop.DemoController.test() )")
    public void check(JoinPoint joinPoint){
        System.out.println("hello"+joinPoint);
        LOGGER.info("hello"+joinPoint);
    }


    @Before("@annotation(CustomAn)")
    public void annotaion(JoinPoint joinPoint,CustomAn  customAn){
        System.out.println("hello custom1"+joinPoint);

        LOGGER.info("hello custom1"+joinPoint);
        LOGGER.info("CustomAn"+customAn);

    }

}
         

Solution

remove additional parameters in your aspect class . Refer to the highlighted code .

Code Changes 

the aspect class method should not have an additional parameter .

  
        


package com.example.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import org.slf4j.Logger;
import org.springframework.stereotype.Component;

@Component@Aspectpublic class MyAspect {

    private static final Logger LOGGER = LoggerFactory.getLogger(MyAspect.class);

    @Before("execution(* com.example.aop.DemoController.test() )")
    public void check(JoinPoint joinPoint){
        System.out.println("hello"+joinPoint);
        LOGGER.info("hello"+joinPoint);
    }


    @Before("@annotation(CustomAn)")
    public void annotaion(JoinPoint joinPoint){
        System.out.println("hello custom1"+joinPoint);

        LOGGER.info("hello custom1"+joinPoint);

    }

}


         
OUTPUT
2020-03-25 22:31:22.076 DEBUG 18068 --- [http-nio-8095-Acceptor] o.apache.tomcat.util.threads.LimitLatch  : Counting up[http-nio-8095-Acceptor] latch=0
2020-03-25 22:31:22.092  INFO 18068 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8095 (http) with context path ''
2020-03-25 22:31:22.107  INFO 18068 --- [main] com.example.aop.DemoApplication          : Started DemoApplication in 8.303 seconds (JVM running for 9.424)




Thanks for reading . Let me know your thoughts in the comments below    .

ec2-user@ec2 Permission denied