Java 使用around advce时仅截取公共方法
我有一个几乎没有公共和私人方法的服务。请注意,我没有此服务的接口Java 使用around advce时仅截取公共方法,java,spring,spring-aop,Java,Spring,Spring Aop,我有一个几乎没有公共和私人方法的服务。请注意,我没有此服务的接口 package com.myservice.rest; public class CustomerService { public Customer getCustomerbyId(String id){ ................... ............. } public Customer getCustomerbySSN(String SSN){ } private boolean ve
package com.myservice.rest;
public class CustomerService {
public Customer getCustomerbyId(String id){
...................
.............
}
public Customer getCustomerbySSN(String SSN){
}
private boolean verfiyCustomer(){
}
}
我有一个方面,有很多建议。我想拦截所有公共方法
@Aspect
@Component
public class ApplicationMonitoring {
@Around("execution(public com.myservice.rest.CustomerService.*(..))")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
}
通过maven
生成预期的名称模式时出错。然而,如果我不将返回类型用作public,并且使用通配符(*),它也会截取我不需要的所有私有方法。Spring文档说您应该:
1创建切入点:
@Pointcut("execution(public * *(..))")
public void anyPublicOperation() {}
2在你的建议中使用这个切入点:
@Aspect
@Component
public class ApplicationMonitoring {
@Around("execution(com.myservice.rest.CustomerService.*(..)) && path_to_class_with_pointcut.anyPublicOperation()")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
}
我可以通过添加返回类型(*)来实现这一点
模式:
<AccessModifier> <ReturnType> <Package/Class> <Method>(<Parameters>)
()
<AccessModifier> <ReturnType> <Package/Class> <Method>(<Parameters>)