Problems with ApplicationListener in Spring Boot

0

I'm trying to implement an event that is monitored by a listener, but Spring does not call the Listener ...

Event:

import org.springframework.context.ApplicationEvent;

public class CustomSpringEvent extends ApplicationEvent {

private static final long serialVersionUID = 1L;    
private String message;

  public CustomSpringEvent(Object source, String message) {
        super(source);
        this.message = message;
  }

  public String getMessage() {
        return message;
  }
}

Listener

@Component
public class CustomSpringEventListener implements ApplicationListener<CustomSpringEvent> {

  @Override
  public void onApplicationEvent(CustomSpringEvent event) {
    System.out.println("MENSAGEM RETORNADA PELO EVENTO: "+event.getMessage());
  }

}

Event call

CustomSpringEvent customSpringEvent = new CustomSpringEvent(this, "ALKSDJFASLKDJFASLKDFJALKSDJFSKDJ");
publisher.publishEvent(customSpringEvent);
    
asked by anonymous 18.04.2018 / 20:57

0 answers