情景:做项目遇到一个情景,同一个应用中,有A包和B包,本来是A包中方法调用B包的方法,现在要求B包中方法调用A包中方法
解决方案:
利用ApplicationContextEvent事件
监听方:
public class AccountChangeEvent extends ApplicationContextEvent {
@Getter
private final String param;
/**
* Create a new ContextStartedEvent.
*
* @param source the {@code ApplicationContext} that the event is raised for
* (must not be {@code null})
*/
public AccountChangeEvent(ApplicationContext source, String param) {
super(source);
this.param=param;
}
}
调用方:
@Resource
private ApplicationContext applicationContext;
//发送事件
applicationContext.publishEvent(new AccountChangeEvent(applicationContext,"这是参数"));