Spring 随便在某个类中获取Spring已经注入的Bean

来源:互联网 发布:网络培训怎么快进 编辑:程序博客网 时间:2024/05/22 05:26

private TestService testService;

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();    

this.testService= (beanName) webApplicationContext.getBean("testService");
原创粉丝点击