2013-09-05 164 views
0

我想指定和建議圍繞在我的API層,它是一組包的所有處理程序:Spring AOP的問題

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

我一直在嘗試下面的代碼:

@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{ 
    ... 
} 

彈簧初始化失敗:

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() 

任何幫助?我使用的是Spring 3.1.1。

回答

2

處理器是AspectJ的表達式語言保留關鍵字,改變你的方法名應該做的伎倆(見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{ 
    ... 
}