Spring直接取得Bean

1,applicationContext.xml中追加定义

<bean id="testService" class="test.TestService" />

2,Java代码中取得

WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); 
TestService testBean = (TestService)wac.getBean("testService")

猜你喜欢

转载自zhuhuide2004.iteye.com/blog/2308253