Affects: All Spring Framework versions

I saw that @Component can easily be used in any annotation that is meta-annotated with @Component, and this custom annotation can be used with Spring's component scanning.

But I can't use @Aspect in the custom composed annotation to annotate a class for AOP, and also the pointcut can't find the annotation in the custom merged annotation .

I provide an example here: https://github.com/zzs007/springaoptest

Comment From: sbrannen

Hi @zzs007,

Thanks for raising your first issue for the Spring Framework!

I have been able to reduce your application to a minimal example using Java Config as follows (with all types declared in the same package).

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Component
@Aspect
public @interface Aop {
}
@Aop
// @Aspect
class MyAspect {

    @Pointcut("@within(org.springframework.stereotype.Service)")
    public void pointcut() {
    }

    @Around("pointcut()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.err.println("Before ...");
        Object obj = joinPoint.proceed();
        if (obj instanceof String) {
            obj = ((String) obj).toUpperCase();
        }
        System.err.println("After: " + obj);
        return obj;
    }

}
@Service
class MyService {

    public String hello() {
        return "Hello";
    }

}
@SpringJUnitConfig
class AspectJMetaAnnotationTests {

    @Test
    void test(@Autowired MyService service) {
        assertThat(service.hello()).isEqualTo("HELLO");
    }

    @Configuration
    @ComponentScan
    @EnableAspectJAutoProxy
    static class Config {
    }

}

Running AspectJMetaAnnotationTests currently results in an exception against the main branch; however, when I annotate MyAspect directly with @Aspect the test passes.

So that gives me something to work with, and I'll report back with my findings later.

Comment From: sbrannen

I discovered that Spring's support for @Aspect relies heavily on AspectJ's own org.aspectj.internal.lang.reflect.AjTypeImpl which does not support @Aspect when used as a meta-annotation.

In light of that, we can say that Spring currently does not support using @Aspect as a meta-annotation due to the aforementioned limitation in AspectJ; however, we will investigate our options.

Comment From: sbrannen

See also: https://github.com/eclipse/org.aspectj/issues/81

Comment From: vishalsingh2972

@zzs007 @sbrannen can you assign this to me if it's still open ?

Comment From: sbrannen

Closing in favor of https://github.com/eclipse-aspectj/aspectj/issues/81.

If it turns out that changes need to be made within the core Spring Framework after AspectJ provides meta-annotation support, this issue can be reopened.