Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.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
Java 使用around advce时仅截取公共方法_Java_Spring_Spring Aop - Fatal编程技术网

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