首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Spring的有关问题

2012-01-03 
Spring的问题WebApplicationContext wac WebApplicationContextUtils.getRequiredWebApplicationContext

Spring的问题
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
IUserService userService = (IUserService)wac.getBean("userService");
代码中出现了这样的2句,有哪位大侠能解释一下吗?
(IUserService)wac.getBean("userService");不知道这一句是不是将一个实例从一个类似池的容器中提取出来?
如果是的话,那么这应该需要一个配置文件来进行控制,以便对IUserService进行管理吧,是哪一个配置文件呢?
请大侠们赐教!谢谢
分不够再加。

[解决办法]
spring 容器对其进行管理
[解决办法]
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context); 
wac会通过上下文从web.xml中去读spring配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring/applicationContext-*.xml</param-value>
</context-param>

IUserService userService = (IUserService)wac.getBean("userService"); 
而这个userService就定义在这些spring配置文件中
[解决办法]

探讨
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
wac会通过上下文从web.xml中去读spring配置文件
<context-param>
<param-name>contextConfigLocation </param-name>
<param-value>/WEB-INF/config/spring/applicationContext-*.xml </param-value>
</context-param>

IUserService userService = (IUserService)wac.getBean("userService");
而这个user…

热点排行