Pointcut expression 'abc(inString)' contai

2019-08-06 13:13发布

问题:

I am new to spring-aop concepts.

I am getting this error during compilation.

org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException: Pointcut expression 'abc(inString)' contains unsupported pointcut primitive 'call'

My aspect is,

@Aspect
@Component
public class BeforeAdvice {

      @Pointcut(value="call(@com.app.test.EncryptDemo * *(String)) && args(inString) && !within(com.app.test.BeforeAdvice)",argNames="inString")
      public void abc(String inString) {};

      @Around(value = "abc(inString)",argNames="inString")
      public Object ourAroundAdvice(ProceedingJoinPoint pjp, String inString) throws Throwable {

          System.out.println("in around");
          return null;
      }
  }

My custom annotation

@Documented
@Target({ ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface EncryptDemo {

}

My entity

@Entity
@Table(name="customer")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Customer {

    @Id
    @GeneratedValue
    private Long id;

    private String somethingPublic;

    private String somethingPrivate;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getSomethingPublic() {
        return somethingPublic;
    }

    public void setSomethingPublic(String somethingPublic) {
        this.somethingPublic = somethingPublic;
    }

    public String getSomethingPrivate() {
        return somethingPrivate;
    }

    @EncryptDemo
    public void setSomethingPrivate(String somethingPrivate) {
        this.somethingPrivate = somethingPrivate;
    }
}

I have added this dependency to pom.

spring-boot-starter-aop

aspectjrt

aspectjweaver

I found one solution but I am not understanding what they are trying to say.

UnsupportedPointcutPrimitiveException on simple AOP example

Please guide me towards this. Any help will be appreciate.

Thanks.

回答1:

Spring uses (by default) proxy based AOP and as such has only limited support for joinpoint expression. The call join point that isn't supported only the execution join point is. The supported join point expressions are documenten here.

Next to that you are trying to apply AOP to a non Spring managed bean this will also not work with a proxy based solution.

For both situations you need to use either load or compile time weaving to make it work.