Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 如何将@Before advice与多个切入点一起使用?_Rest_Spring Mvc_Annotations_Aspectj_Spring Aop - Fatal编程技术网

Rest 如何将@Before advice与多个切入点一起使用?

Rest 如何将@Before advice与多个切入点一起使用?,rest,spring-mvc,annotations,aspectj,spring-aop,Rest,Spring Mvc,Annotations,Aspectj,Spring Aop,我已经编写了一个@Before通知,用于调用以下属于名为MPIController的同一类的方法 TransactionType 是我的自定义注释接口 方法是: 1. @RequestMapping(value = "/getPatient", method = { RequestMethod.POST,RequestMethod.PUT }, consumes = "application/json", produces = "application/json") @Transactio

我已经编写了一个@Before通知,用于调用以下属于名为MPIController的同一类的方法

TransactionType  
是我的自定义注释接口

方法是:

1.
@RequestMapping(value = "/getPatient", method = { RequestMethod.POST,RequestMethod.PUT }, consumes = "application/json", produces = "application/json")
@TransactionType(value = "FETCH_PATIENT")
public @ResponseBody
FetchPatientResponse fetchPatientDemographics(
        @RequestBody String jsonObject, HttpServletResponse response,
        HttpServletRequest request, BindingResult error) {
       ...
       }

我的建议是这样的

@Before("execution(* com.rest.controller.MPIController.*(..)) &&args(jsonObject,..) && @annotation(transactionType) ")
public void log(String jsonObject,TransactionType transactionType){..}
对于“fetchPatientDemographics()方法,@Before通知被正确调用,但是对于其余两个方法它不起作用

你能告诉我我做错了什么吗


方法2和3是从同一类中的其他方法调用的。它们不是直接调用的。这可能是一个问题吗?

Spring AOP只能建议公共方法。如果您也想建议私有方法,则必须使用不同的AOP实现,如普通AspectJ。Hi@sheltem,我使用的是AspectJ,但问题出在这里仍然存在。即使我公开了这两种方法,它仍然不起作用!这听起来好像你认为你在使用AspectJ,但实际上你仍然在使用Spring AOP(除了语法之外,它与AspectJ没有任何共同之处)。也许你想再次检查和/或发布一个完整的Spring示例,包括配置文件。
3. 
@TransactionType(value = "REGISTER_PATIENT")
private PersistResponse RegisterPatient(String jsonObject,String patientDemo,
        String fromCode) {..}
@Before("execution(* com.rest.controller.MPIController.*(..)) &&args(jsonObject,..) && @annotation(transactionType) ")
public void log(String jsonObject,TransactionType transactionType){..}