原来:ChannelInfoService channelInfoServiceImpl = ac.getBean(ChannelInfoServiceImpl.class);
ChannelInfoService channelInfoServiceImpl = SpringUtils.getApplicationContext().getBean(ChannelInfoServiceImpl.class);
但是这种获取bean的方式却会导致BeanFactory not initialized or already closed - call 'refresh' before accessing的错误,经过查阅相关资料,发现是SpringUtils自身没有注册的原因,如果按照下面这样改就不会有问题:
AbstractApplicationContext ac = new ClassPathXmlApplicationContext("classpath:spring/ApplicationContext.xml");
ChannelInfoService channelInfoServiceImpl = ac.getBean(ChannelInfoServiceImpl.class);
然后用channelInfoServiceImpl可以调用里面的方法。