0

I use aspectj and spring boot. I am trying to log a message when a method(boolean value) is called. aspects are working in general, but my expression for catching must be wrong

it is working with (but is of cause catching every method):

    @Before("execution(* de.fhb..*(..))")

also working (catching with only one parameter)

    @Before("execution(* de.fhb..*(*))")

now the problem:

    @Before("execution(* de.fhb..*(boolean))")

or

    @Before("execution(* de.fhb..*(java.lang.Boolean))")

does not work. Any help? The mistake must be between execution(* de.fhb..*((my error i think))

here my files (getter && setter are generated with lombok):

pojo:

package de.fhb.showcase;

@Getter @Setter
public class Show {

    private String name;
    private boolean live;

    public void makeShowLive(boolean value) {
        live = value;
    }
}

aspect:

package de.fhb.aop;

import javax.inject.Named;

import lombok.extern.java.Log;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
@Named
@Log
public class CleanCodeAspect {

    @Before("execution(* de.fhb..*(..))")
    public void checkStyleBooleanParameter() {

        log.warning("You used a method with only one boolean parameter. "
                + "Refactor it into 2 methods with True, False at the end.");
    }

}
svenhornberg
  • 14,376
  • 9
  • 40
  • 56
  • Try `java.lang.boolean`. I also doubt that creating to methods like `setLiveTrue()` or `setLiveFalse()` is clean code. It should be more functional like `enable()`/`disable()` or `show()`/`hide()`. But that could be just me. – M. Deinum Oct 28 '14 at 15:10
  • java.lang.boolean gives me that error: warning no match for this type name: java.lang.boolean [Xlint:invalidAbsoluteTypeName] at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression and with the clean code i got this idea from http://www.planetgeek.ch/wp-content/uploads/2013/06/Clean-Code-V2.1.pdf (Selector / Flag Arguments) it is only a simple example (not the standard logging, time tracing). but thx for your advice – svenhornberg Oct 28 '14 at 15:35

1 Answers1

0

Your syntax is correct, see and test for yourself without Lombok. I think the problem is Lombok interfering with AspectJ, maybe similar as described here (follow the links there to learn more details). It might be another issue, but that would be my first bet.

Community
  • 1
  • 1
kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • I removed lombok from my pojo but it does not work with boolean. * work fine. Should i post the link to my github repo? – svenhornberg Oct 28 '14 at 16:22
  • Yes, please. I tried with native AspectJ, not with Spring. I am not a Spring user normally. – kriegaex Oct 28 '14 at 22:06
  • got it working with the standard sample here https://github.com/svenhornberg/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-aop . I will look for the difference Named and Component wasnt the reason – svenhornberg Oct 29 '14 at 12:23