import com.sanding.attachfile.AttachfileApplication;
import com.sanding.attachfile.event.AnotherEvent;
import com.sanding.attachfile.event.MyEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
@RunWith(SpringRunner.class)
@SpringBootTest(classes={AttachfileApplication.class})
public class SpringEventLisnerTest {
@Autowired
ApplicationContext applicationContext;
@Test
public void test() {
// 业务实体
MyEvent myEvent = new MyEvent(this, "北京", "范柳原", new Date());
//发布事件
this.applicationContext.publishEvent(myEvent);
// 业务实体
AnotherEvent anotherEvent = new AnotherEvent(this, "北京", "白流苏", new Date());
//发布事件
this.applicationContext.publishEvent(anotherEvent);
}
}
测试结果
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@1af677f8 rejected from java.util.concurrent.ThreadPoolExecutor@7a55fb81[Running, pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submit(ThreadPoolTaskExecutor.java:341)