Pointcut expression 'abc(inString)' contains unsupported pointcut primitive 'call'

独自空忆成欢 提交于 2019-12-11 12:14:24

问题


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.



来源:https://stackoverflow.com/questions/31416302/pointcut-expression-abcinstring-contains-unsupported-pointcut-primitive-cal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!