2

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.

Community
  • 1
  • 1
Jimmy
  • 1,719
  • 3
  • 21
  • 33
  • You are using the `call` join point that isn't supported by spring only the `execution` join point is. See http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-pointcuts-designators – M. Deinum Jul 15 '15 at 06:32
  • 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 Jul 15 '15 at 06:47
  • 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 Jul 15 '15 at 07:00
  • Okay thank you very much. I will try to use load or compile time weaving. – Jimmy Jul 15 '15 at 07:08
  • @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 Jul 15 '15 at 15:06
  • @M.Deinum: I implemented compile time weaver but my annotation is never called. it is called if I annotated any method of spring bean however method in entity is never called. I did all the configuration which required. I also added '-javaagent:spring-instrument.jar' in my vm argument. I followed this example https://github.com/renxunsaky/spring-aop-weaving-jar please help us. Please give something in details. Thanks. – Jimmy Jul 15 '15 at 19:11
  • When using compile time weaving you don't need the agent as the code becomes part of the class. Make sure that your aspect is actually woven into your code (you would need to enable debug logging whilst running the aj compiler). – M. Deinum Jul 16 '15 at 05:27

1 Answers1

4

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.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224