我正在使用Spring ApplicationEventPublisher发布事件
发布和发布者的方法
@Autowired
private ApplicationEventPublisher eventPublisher;
private void publishContributorUpdate(long contributorId, boolean isOwner){
var upe = new DeactivateContributorEvent(this);
upe.setContributorId(contributorId);
upe.setOwner(isOwner);
eventPublisher.publishEvent(upe);
}
事件类:
public class DeactivateContributorEvent extends ApplicationEvent
听众在这里
@Component
public class ContributorDeactivateEventListener {
@Autowired
private ContributorDao contributorDao;
@EventListener
public void onContributorDeactivation(final DeactivateContributorEvent event) {
contributorDao.updateContributor(event.getContributorId(),event.isOwner(),false);
}
}
因此,该事件已发布,正如我所见但未读。可能是什么原因呢?我正在使用spring-boot 2.1.3