2
votes

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
You are using the call join point that isn't supported by spring only the execution join point is. See docs.spring.io/spring/docs/current/spring-framework-reference/… - M. Deinum
Hi @M. Deinum, thanks for the documentation. I have also tried with the execution join point but my aspect is never called. what should I do ? - Jimmy
Because Spring will only intercept spring beans and I highly doubt that the bean you are trying to intercept is a bean managed by spring. Spring will only apply AOP to classes it knows (i.e those that are beans) everything else is ignored. If you want that use load or compile time weaving instead of Springs proxied based approach. - M. Deinum
Okay thank you very much. I will try to use load or compile time weaving. - Jimmy
@M.Deinum: Please transform your comment into an actual answer in order to get it accepted and the question closed. I know you are a humble guy who often posts comments worth being rewarded as an answer and you don't need the reputation points. But the answer needs to be closed. :-))) - kriegaex

1 Answers

4
votes

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.