Search code examples
aopspring-aop

Can the parent of an Introduction be a class?


In the official documentation it is claimed that the parent has to be an interface, yet in the example given it is a class (class UsageTracking). How comes?

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-introductions

@Aspect
public class UsageTracking {

    @DeclareParents(value="com.xzy.myapp.service.*+", defaultImpl=DefaultUsageTracked.class)
    public static UsageTracked mixin;

    @Before("com.xyz.myapp.CommonPointcuts.businessService() && this(usageTracked)")
    public void recordUsage(UsageTracked usageTracked) {
        usageTracked.incrementUseCount();
    }

}

Solution

  • From the documentation example : https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-introductions

    • The aspect class is UsageTracking
    • The parent interface is UsageTracked
    • The implementation class is DefaultUsageTracked

    The example looks valid. The confusion here appears to be about the Aspect class name and the interface name.