1

I am currently working on a REST API that will be using the Spring framework. My team is looking into using some AOP for the purpose of maintaining cross-cutting concerns.

I have had success with Spring AOP, but later realized that it may not be powerful enough to handle things that I would like to do.

I have been trying to get AspectJ integrated into our Spring application, but have had little success. The spring documentation does not seem to be fully fleshed out and Google searches have been tough because articles often mix-up Spring AOP and AspectJ integrated in Spring.

I was wondering if there are some tips, pointers or walk-throughs that use AspectJ in the Spring Framework.

The problem that I am trying to solve is that I would like to set a variable on an class when another setter is called. Spring AOP fails to be able to do this because it is proxy based and can only proxy beans it controls. The setters that I am calling are model class and will not be beans handled by Spring.

I have decided to switch to the aspectj-maven compile plugin, but I am getting the following error when I turned on verbose:

"can not build thisJoinPoint lazily for this advice since it has no suitable guard [Xlint:noGuardForLazyTjp]"

This is my current aspect

public aspect SkynetServiceAspect1 {


@Before("execution(* com.company.application.service.ServiceImpl..*(..))")
public void loggingLoggerGuy(JoinPoint jp) {
    Object[] oArray = jp.getArgs();
    System.out.println("***************************************************************************************************************");
    System.out.println("I am this method: "+  jp.getSignature().getName() + "with the following arguments" + oArray.toString()+"!");

}

}

This is the error I receive upon running a maven clean install

 [INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] can not build thisJoinPoint lazily for this advice since it has no suitable guard [Xlint:noGuardForLazyTjp]
        C:\workspaces\Newport-1\OAuthPOCAOP\target\classes!com\company\application\aspect\SkynetServiceAspect1.class:18

[WARNING] advice defined in com.company.application.aspect.SkynetServiceAspect1 has not been applied [Xlint:adviceDidNotMatch]
        C:\workspaces\Newport-1\OAuthPOCAOP\target\classes!com\company\application\aspect\SkynetServiceAspect1.class:18

Any help would be greatly appreciated, thanks.

  • What are you planning to use, compile time weaving or load time weaving? – Nándor Előd Fekete Dec 15 '16 at 19:58
  • My goal is attempt to use load time weaving if possible. My web application is running on a tomcat server. There was at one point a custom class loader called "TomcatInstrumentableClassLoader", but I read that this was not needed if you are using Tomcat 8 which my application will be running on. – Barry Fleming Dec 15 '16 at 20:50
  • I have switched to compile time weaving using the aspectj maven plugin. I seem to be getting further but I am now having an issue with the actual weaving of my aspect. – Barry Fleming Dec 19 '16 at 18:38
  • You need to update your post with the aspect for which you're getting the error. Is it a terminal error btw? Or just some warning? – Nándor Előd Fekete Dec 19 '16 at 18:58
  • Added my aspect and the error I get when I attempt a maven clean install – Barry Fleming Dec 19 '16 at 20:16
  • That's a warning, not an error, it just tells you that your aspect will be executed sub-optimally, [read here](https://dev.eclipse.org/mhonarc/lists/aspectj-users/msg05984.html) for the details on why. It practically tells you that whenever your aspect executes, aspectj will need to build the object for the `thisJoinPoint` instance upfront because it couldn't optimize it away. But since you're querying the joinpoint in the advice anyway, it doesn't make a difference. – Nándor Előd Fekete Dec 19 '16 at 20:28
  • `Xlint:adviceDidNotMatch` means that no matching joinpoints for your pointcut are found in the compiled code. This indicates that either you have a typo/error in your pointcut or the target classes are unavailable during compile/weaving time. It would be helpful to see some target code you expect to be intercepted by your aspect including package and class name. – kriegaex Dec 31 '16 at 11:22

0 Answers0