Сначала реализуйте собственный издатель ApplicationEvent
Код: Выделить всё
public class CustomEventPublisher implements ApplicationEventPublisher {
private final ApplicationEventPublisher publisher;
private final Logger logger = getLogger(CustomEventPublisher.class);
public CustomEventPublisher(ApplicationEventPublisher publisher) {
this.publisher = publisher;
}
@Override
public void publishEvent(ApplicationEvent event) {
logger.info("sending an event...");
publisher.publishEvent(event);
}
//.....
}
Код: Выделить всё
@Configuration
public class CustomEventPublisherConfig {
@Bean
@Primary
public ApplicationEventPublisher getCustomEventPublisher(ApplicationEventPublisher publisher , RabbitTemplate rabbitTemplate) {
return new CustomEventPublisher(publisher, rabbitTemplate);
}
}
Код: Выделить всё
public void pub() {
publisher.publishEvent(new Event(this , 1));
}
@EventListener
public void sub(Event e) {
this.value = e.getValue();
}
затем я попытался определить совокупный корень
Код: Выделить всё
@Entity
public class AggregateRoot extends AbstractAggregateRoot {
@Id
@GeneratedValue
private Long id;
private int value = 0;
public AggregateRoot setValue(int value) {
registerEvent(new Event(this , value));
return this;
}
}
Код: Выделить всё
public void pub() {
repository.save(new AggregateRoot().setValue(1));
}
Есть предложения по решению этой проблемы?
Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/640 ... tpublisher
Мобильная версия