0

So, I am working with Spring boot aop

used implementation 'org.springframework.boot:spring-boot-starter-aop' in build.gradle

Issue: I added @LogMetrics annotation in following functions

    @LogMetrics
    public Employee createEmployee(String name, String empId)

    @LogMetrics
    public Employee oneparam(String a) {}

    @LogMetrics
    public Employee twoparam(String a, String b) {}

    @LogMetrics
    public Employee threeparam(String a, String b, String c) {}

but advice is not printing as per my requirement. It is only printing for createEmployee function

I used

@Before(value = "@annotation(com.paradox.springsample.annotations.LogMetrics) || within(com.paradox.springsample.annotations.LogMetrics)")

Can someone help me explain why the logs are not getting printed for above functions ? Is something wrong in my code or any implementation detail i am missing out Intellij was able to detect advice methods though

curl used:: curl -X GET 'http://localhost:9000/employee/add?name=rajat&empId=123'

Github url for code: https://github.com/rajat19/spring-aop-issue You can clone the repo and test it out. I can explain more on this if someone wants to test and check

Things I tried-

  1. adding args(a, b) etc. to distinguish functions inside @Before
  2. making return type same for all functions
  3. using execution(* com.paradox.springsample.services.EmployeeService.*(..))
  • Short version of my answer I linked to when closing this question as a duplicate: Either use native AspectJ and avoid Spring AOP's dynamic proxies or auto-wire the proxy into the class (ugly, but easy and working): `@Autowired EmployeeService INSTANCE;` and then `Employee a = INSTANCE.oneparam("");` etc. – kriegaex Mar 07 '22 at 11:41
  • @kriegaex thanks for your help. Let me test it out the changes you suggested – Rajat Srivastava Mar 07 '22 at 12:54

0 Answers0