InitializingBean 使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41317565/article/details/87620932
/**
 * @author zhangqiang
 * @date 2019-02-18
 */
@Log4j2
@Component
public class OnlineOfferFactory implements InitializingBean {

    private static final List<AbstractOnlineOfferService> ABSTRACT_ONLINE_OFFER_SERVICE_LIST = new ArrayList<>();

    @Autowired
    private ApplicationContext app;

    @Override
    public void afterPropertiesSet() throws Exception {

        String[] beanNames = app.getBeanNamesForType(AbstractOnlineOfferService.class);
        for(String beanName:beanNames) {
            ABSTRACT_ONLINE_OFFER_SERVICE_LIST.add(app.getBean(beanName, AbstractOnlineOfferService.class));
        }
        log.info(String.format("初始化在线offer处理类,一共%d个处理类", ABSTRACT_ONLINE_OFFER_SERVICE_LIST.size()));
    }

    public static List<AbstractOnlineOfferService> getCheatCheckList(){
        return ABSTRACT_ONLINE_OFFER_SERVICE_LIST;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_41317565/article/details/87620932