有時候我們會出現無法用注解 @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刪除。