Search code examples
aopspring-aoppointcut

@target pointcut throws IllegalStateException


In Spring boot AOP application I have a pointcut @target(MyAnnotation) || @annotation(MyAnnotation). Advice should be executed if MyAnnotation is put either on executing object annotated with this annotation or on annotated method.

When I run application I get

java.lang.IllegalArgumentException: Cannot subclass final class org.springframework.cloud.sleuth.log.Slf4jScopeDecorator

A similar problem is discussed here but there it seems that pointcut is too wide and mine is not as I have only few annotated classes with MyAnnotation in the project.

I put this annotation to feign client interface, like this.

@MyAnnotation
@FeignClient(name="some-name", url="http://test.url")
public interface MyClient {
    @RequestMapping(method = RequestMethod.GET, value = "/endpoint")
    List<Store> getSomething();
}

Any ideas what's wrong with my pointcut?


Solution

  • Ok, after hours of investigation I replaced my pointcut with this one

    @Around("execution(* (@MyAnnotation *).*(..)) || execution(@MyAnnotation * *(..))")
    

    As explained here I used only execution to avoid proxy creation. Hope this helps