1

I have a simple counter

@Aspect
@Component 
public class Countter {

  @After("@annotation(com.example.MessageAnnotation)")
  public void increment(JoinPoint point){
    //do increment
  }
}

And I have messages listener

@Component
@AllArgsConstructor
@FieldsDefaults(level=Private, makeFinal = true)
public class Handler {

  @NotNull UserRepository repo;
  @NotNull MessageClient client;

  @MessageAnnotation // <- here annotation works, an I can pass to increment method!!!
  public void handleEvent(Event event) {
    User user = repo.fondById(event.getId);
    user.ifPresent(o - > send(o))

  }

  @MessageAnnotation // <- I need to pass to increment method from this method because the user sometimes is 
  public void send(User user) { // not present, but it doesn't work.
    //do send user
  }
}

What is my problem? Why I cant pass to increment method from method from another method?

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • Could you please describe a little better what you would expect to happen and what actually is happening? – Kaj Hejer Mar 31 '21 at 08:24
  • I can't pass to increment method from send method, and I don't understand why – Семен Немытов Mar 31 '21 at 09:15
  • When you call one bean method from another, it's not going to have any aspects applied. You're just directly accessing another method, bypassing any proxies. See [this answer](https://stackoverflow.com/questions/5152686/self-injection-with-spring) for possible workarounds – crizzis Mar 31 '21 at 09:40

0 Answers0