需要帮助创建利用方法注释中的值的特定切入点
我有以下方法
@AutoHandling(slot = FunctionalArea.PRE_MAIN_MENU)
@RequestMapping(method = RequestMethod.GET)
public String navigation(ModelMap model) {
logger.debug("navigation");
...
//First time to the Main Menu and ID-Level is ID-1 or greater
if (!callSession.getCallFlowData().isMainMenuPlayed()
&& callSession.getCallFlowData().getIdLevel() >= 1) {
// Call Auto Handling
logger.info("Call AutoHandling");
autoHandlingComponent.processAutoHandling();
}
...
return forward(returnView);
}
基本上我想做的是在 processAutoHandling() 上有一个切入点 但是在@After中,我需要使用@AutoHandling的slot()
我尝试过这个,但它没有被调用
@Pointcut("execution(* *.processAutoHandling())")
public void processAutoHandleCall() {
logger.debug("processAutoHandleCall");
}
@Around("processAutoHandleCall() &&" +
"@annotation(autoHandling) &&" +
"target(bean) "
)
public Object processAutoHandlingCall(ProceedingJoinPoint jp,
AutoHandling autoHandling,
Object bean)
throws Throwable {
...
I have the following method
@AutoHandling(slot = FunctionalArea.PRE_MAIN_MENU)
@RequestMapping(method = RequestMethod.GET)
public String navigation(ModelMap model) {
logger.debug("navigation");
...
//First time to the Main Menu and ID-Level is ID-1 or greater
if (!callSession.getCallFlowData().isMainMenuPlayed()
&& callSession.getCallFlowData().getIdLevel() >= 1) {
// Call Auto Handling
logger.info("Call AutoHandling");
autoHandlingComponent.processAutoHandling();
}
...
return forward(returnView);
}
Basically what I want to do, is have a pointcut on processAutoHandling()
But in the @After, I need to use the slot() for @AutoHandling
I tried this, but it does not get called
@Pointcut("execution(* *.processAutoHandling())")
public void processAutoHandleCall() {
logger.debug("processAutoHandleCall");
}
@Around("processAutoHandleCall() &&" +
"@annotation(autoHandling) &&" +
"target(bean) "
)
public Object processAutoHandlingCall(ProceedingJoinPoint jp,
AutoHandling autoHandling,
Object bean)
throws Throwable {
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为此使用虫洞设计模式。我正在说明使用基于 AspectJ 字节码的方法和语法,但如果您使用 Spring 的基于代理的 AOP,您应该能够使用显式 ThreadLocal 获得相同的效果。
You can use the wormhole design pattern for this. I am illustrating using AspectJ byte-code based approach and syntax, but you should be able to get the same effect using an explicit ThreadLocal if you are using Spring's proxy-based AOP.
a)它不起作用,您试图匹配两个不同的东西:
processHandleCall()
匹配内部方法执行autoHandlingComponent.processAutoHandling()
而@annotation (autoHandling)
与外部方法执行navigation(ModelMap model)
b) 由于您显然是在尝试向控制器提供建议,因此有一些注意事项:
proxy- target-class=true
一切都应该按原样工作,只需确保您没有任何最终方法(a) It can't work, you are trying to match two different things:
processHandleCall()
matches the inner method executionautoHandlingComponent.processAutoHandling()
while@annotation(autoHandling)
matches the outer method executionnavigation(ModelMap model)
b) since you are obviously trying to advise a Controller, there are a few caveats:
proxy-target-class=true
everything should work as is, just make sure you don't have any final methods@RequestMapping
etc annotations must be on the interface, not the implementing class as described in this section of the Spring MVC reference docs