1 2 |
applicationContext.publishEvent(new TestEvent()); |
1 2 3 4 5 6 7 8 |
@Async @EventListener public void onApplicationEvent(TestEvent event) throws Exception { Thread.sleep(10000L); log.info("event:" + event.getClass().getCanonicalName()); throw new Exception("fuck you"); } |
1 2 3 4 5 6 7 8 9 |
@EnableAsync @SpringBootApplication public class Server { public static void main( String[] args ) { SpringApplication.run(Server.class); } } |
1 2 3 4 5 6 |
@Bean(value="taskExecutor") public TaskExecutor getTaskExecutor () { ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(); return executor; } |
1 2 3 4 5 6 7 8 9 10 |
@Bean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME) public SimpleApplicationEventMulticaster getApplicationEventMulticaster(BeanFactory beanFactory) { log.info("getApplicationEventMulticaster called"); ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(); SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster(beanFactory); multicaster.setTaskExecutor(executor); multicaster.setErrorHandler(TaskUtils.getDefaultErrorHandler(true)); return multicaster; } |
Posted in: spring practise
Comments are closed.