Cannot get AspectJ to work with JAX-RS services

I am trying to get AOP to work in the JAX-RS service. It works with Spring objects, but not my JAX-RS services. My assumption is that it does not work, because Jersey creates my JAX-RS objects, not Spring. How can I get an AOP to work with my JAX-RS services?

Here's how I declare my aspects:

@Pointcut("execution (* com.ancestry.academy.api.user.UserService.*(..))")
public void apiMethods() {}

@Around("com.ancestry.academy.api.ApiAdvisor.apiMethods()")
public Object aroundApi(ProceedingJoinPoint pjp) throws Throwable
{
    System.out.println("User Service API called");

    return pjp.proceed();
}

@Pointcut("execution (* com.ancestry.academy.services.user.UserManagerImpl.*(..))")
public void serviceMethods() {}

@Around("com.ancestry.academy.api.ApiAdvisor.serviceMethods()")
public Object aroundService(ProceedingJoinPoint pjp) throws Throwable
{
    System.out.println("User Maanageer API called");

    return pjp.proceed();
}

The first aspect concerns my JAX-RS service, and this is the one that does not work. The second aspect is the Spring injection bean, which provides business logic, and it works.

There is nothing special about UserService except that it extends SpringBeanAutowiringSupport.

I have <aop:aspectj-autoproxy/>spring in my XML file.

+3
source share

All Articles