Question

I am doing Spring Aspect Oriented Programming with annotations in Java. I have an Aspect LogAOP:

@Aspect
public class LogAOP {

  @DeclareParents(value="beans.service.*+",     //Line 1
                  defaultImpl= EventImpl.class)
  public static Event mixin;

  @Before("com.beans.business.businessService() &&" +
          "this(abc)")
  public void usage(Event abc) {
    abc.increment();
  }

}

I am not able to understand the significance of '+' symbol in Line 1 in value attribute of @DeclareParents annotation. Beacuse even if I remove this + symbol, the program is running fine. I have also searched in official documentation of Spring AOP (http://docs.spring.io/spring/docs/2.5.4/reference/aop.html) , nothing is mentioned there.

Was it helpful?

Solution

Using + after a class name or interface name is used to match that class or interface, and all it's subclasses. So, the pointcut expression in this case:

@DeclareParents(value="beans.service.*+",     //Line 1
              defaultImpl= EventImpl.class)
public static Event mixin;

...will match any interfaces or class defined in package beans.service, and also any subclass or implementing class of those classes and interfaces. It may be needed because, the implementing classes might not be in the beans.service package. In your case, you're not seeing the effect because may be all your implementing classes are in the same package. Try implementing an interface in beans.service package, and put the implementing class in a different package. I guess, you'll see the difference then.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top