/**
* 业务逻辑
*
*/
public void test(){
//todo
//.....
//异步执行事件,方法直接返回true
applicationEventPublisher.publishEvent(new asyEvent("123"));
}
/**
* 监听
*
*/
import org.springframework.context.ApplicationEvent;
@Getter
@Setter
@ToString
public class asyEvent extends ApplicationEvent {
private String source;
public asyEvent(String source) {
super(source);
this.source = source;
}
}
/**
* 接收执行
*
*/
import org.springframework.context.event.EventListener;
@Component
public class ApplicationEventListener {
@Autowired
private GoodService goodService;
@EventListener
public void asyEvent(asyEvent event) {
Logs.info("asyEvent event: {}", event);
goodService.get(event.getSource());
}
}