@Test public void testCustomEvent() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-event.xml"); EmailService emailService = context.getBean(EmailService.class); emailService.sendEmail("john.doe@example.org", "hands up, shit..."); }
public void sendEmail(String address, String text) { if (blackList.contains(address)) { BlackListEvent event = new BlackListEvent(this, address, text); publisher.publishEvent(event); return; } System.out.println("send email..."); System.out.println("email address : " + address + ", text: " + text); }
EmailService implements ApplicationEventPublisherAware { public void sendEmail(String address, String text) { if (blackList.contains(address)) { BlackListEvent event = new BlackListEvent(this, address, text); publisher.publishEvent(event); return; } System.out.println("send email..."); System.out.println("email address : " + address + ", text: " + text); } }
EmailService implements ApplicationEventPublisherAware { public void sendEmail(String address, String text) { if (blackList.contains(address)) { BlackListEvent event = new BlackListEvent(this, address, text); publisher.publishEvent(event); return; } System.out.println("send email..."); System.out.println("email address : " + address + ", text: " + text); } EmailService(); }
EmailService implements ApplicationEventPublisherAware { public void sendEmail(String address, String text) { if (blackList.contains(address)) { BlackListEvent event = new BlackListEvent(this, address, text); publisher.publishEvent(event); return; } System.out.println("send email..."); System.out.println("email address : " + address + ", text: " + text); } EmailService(); void setBlackList(List<String> blackList); @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); void sendEmail(String address, String text); }
EmailService implements ApplicationEventPublisherAware { public void sendEmail(String address, String text) { if (blackList.contains(address)) { BlackListEvent event = new BlackListEvent(this, address, text); publisher.publishEvent(event); return; } System.out.println("send email..."); System.out.println("email address : " + address + ", text: " + text); } EmailService(); void setBlackList(List<String> blackList); @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); void sendEmail(String address, String text);  }