dr.house
dr.house

Reputation: 190

Spring AOP problems

I would like to specify and advice around all handlers in my API layer, which is the set of packages:

ox.server.meta.api.v1
ox.server.meta.api.v2
ox.server.meta.api.v2_1
ox.server.meta.api.v2_2

I've been trying the following code:

@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
private void handler() {}

@Pointcut("within(ox.server.meta.api..*)")
private void controller() {}

@Around("handler() && controller()")
public Object aroundAllHandlers(ProceedingJoinPoint pjp) throws Throwable{
    ...
}

Spring initialization fails with:

Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 8
handler() && controller()
        ^
:
java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 8
handler() && controller()

Any help? I'm using Spring 3.1.1.

Upvotes: 0

Views: 1000

Answers (1)

Sergi Almar
Sergi Almar

Reputation: 8414

Handler is a reserved keyword in the AspectJ expression language, changing your method name should do the trick (see http://www.eclipse.org/aspectj/doc/next/progguide/semantics-pointcuts.html).

@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
private void apiHandler() {}

@Pointcut("within(ox.server.meta.api..*)")
private void controller() {}

@Around("apiHandler() && controller()")
public Object aroundAllHandlers(ProceedingJoinPoint pjp) throws Throwable{
    ...
}

Upvotes: 2

Related Questions