有时候我们会出现无法用注解 @Autowired 注入bean的情况,这个时候可以
通过contextLoader获取
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); BeanService beanService = (BeanService)ctx.getBean("beanID");
这里的beanID为xml文件中对应的<bean id="beanID">
有时候我们会出现无法用注解 @Autowired 注入bean的情况,这个时候可以
通过contextLoader获取
WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); BeanService beanService = (BeanService)ctx.getBean("beanID");
这里的beanID为xml文件中对应的<bean id="beanID">
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。