通过Spring的哪个类的哪个方法得到bean

来源:百度知道 编辑:UC知道 时间:2024/06/20 17:37:21

BeanFactory bean = new ClassPathXmlApplicationContext("applicationContext.xml");
XXService service = (XXService) bean.getBean("beanName");

一楼的方法正确。获取方式建议做成工具类。

一楼方法正解