1,applicationContext.xml中追加定义
<bean id="testService" class="test.TestService" />
2,Java代码中取得
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
TestService testBean = (TestService)wac.getBean("testService")
本文介绍如何在Spring框架中定义并加载自定义的服务bean,通过在applicationContext.xml文件中配置bean定义,并演示了如何在Java代码中通过ContextLoader获取当前Web应用的ApplicationContext实例,进而获取所需的bean。
1,applicationContext.xml中追加定义
<bean id="testService" class="test.TestService" />
2,Java代码中取得
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
TestService testBean = (TestService)wac.getBean("testService")
1170

被折叠的 条评论
为什么被折叠?