@Component publicclassCustomerListenerimplementsApplicationListener<CustomerEvent>{ @Override publicvoidonApplicationEvent(CustomerEvent event){ System.out.println("CustomerListener listening: CustomerEvent has been triggered, event name is " + event.getName()); } }
CustomerListener listening: CustomerEvent has been triggered, event name is click
如果再加入一个监听者呢?是否能通知到
1 2 3 4 5 6 7
@Component publicclassExtraListenerimplementsApplicationListener<CustomerEvent> { @Override publicvoidonApplicationEvent(CustomerEvent event){ System.out.println("ExtraListener listening: CustomerEvent has been triggered, event name is " + event.getName()); } }
结果
1 2
CustomerListener listening: CustomerEvent has been triggered, event name is click ExtraListener listening: CustomerEvent has been triggered, event name is click