1. 获取到ApplicationContext
public class MySource extends XXSource implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
2. 获取要使用的bean
Filter filter = null;
try {
filter = applicationContext.getBean(beanName, Filter.class);
} catch (Exception e) {
e.printStackTrace();
}