我可以在执行来自Angular的Rest API之前调用一个方法我正在从角度进行一个后期休息调用(来自activiti的预定义API)我需要在执行基于方法响应的其余API之前调用一个方法我必须决定是否要调用API。可以使用spring AOP吗?请提供您的建议,并给我任何参考链接,以便我可以负责实施
[POST] http://localhost:8080/myapp/test
before this rest call i have to call a method based on the response i have to decide whether i have to call api or not[some how i traps my request and then navigate to the api]
答案 0 :(得分:0)
继续评论,@ Narendra,你不必修改你的控制器,我的意思是创建这样一个方面
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMapping() {}
@Pointcut("within(de.some.package.controller.*) || within(de.some.package.aspect.*)")
public void myController() {}
@Around("requestMapping() && myController()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
//This will be called before and after any method in the package controller or any method with @RequestMapping annotaion is called
Object result= joinPoint.proceed();
}
这是建议,它可以让您更好地控制方法调用。您也可以使用@Before
这是通过Java Annotations完成的。我相信你也可以从xml做同样的事情。以下是一些例子
http://howtodoinjava.com/spring/spring-aop/aspectj-before-advice-example/
https://www.mkyong.com/spring/spring-aop-examples-advice/