spring 注解实现事件监听

1.public class OrderEvent {

private String price;


public String getPrice() {
return price;
}


public void setPrice(String price) {
this.price = price;
}

}

2.    @Component
public class OrderListener {

@EventListener
public void macthPrice(OrderEvent event){
System.out.println("订单监听器");
}


}

3.public class DealTest {

    @Autowired
    ApplicationContext applicationContext;
    
    @Test
    public void orderMacth(){
    OrderEvent event = new OrderEvent();
    applicationContext.publishEvent(event);
    }


}

猜你喜欢

转载自blog.csdn.net/hansplay/article/details/79507354
今日推荐