Struts和Spring集成配置的一点小问题 收藏
在struts-config.xml文件里面如下配置时候:
<
plug-in
className
=
"org.springframework.web.struts.ContextLoaderPlugIn"
>
<
set-property
property
=
"contextConfigLocation"
value
=
"/WEB-INF/dataAccessContext-local.xml,
/WEB-INF/applicationContext.xml,
/WEB-INF/applicationContext-action.xml,
/WEB-INF/applicationContext-hibernate.xml,
/WEB-INF/modules/coreConfiguration/applicationContext-hibernate.xml,
/WEB-INF/modules/coreConfiguration/applicationContext-service.xml"
/>
<!--
<set-property property="contextConfigLocation"
value="/WEB-INF/dataAccessContext-jta.xml,
/WEB-INF/applicationContext.xml,
/WEB-INF/applicationContext-ibatis.xml,
/WEB-INF/applicationContext-service.xml,
/WEB-INF/applicationContext-action.xml"/>
-->
</
plug-in
>
运行action里面的这两条语句:
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext());
cardstatusService = (CardstatusService) ctx.getBean("cardstatusService");则取不到cardstatusService 实例。
cardstatusService = (CardstatusService) ctx.getBean("cardstatusService");则取不到cardstatusService 实例。
如果是在web.xml文件里面这样配置:
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
/WEB-INF/dataAccessContext-local.xml,
/WEB-INF/applicationContext.xml,
/WEB-INF/applicationContext-action.xml,
/WEB-INF/applicationContext-hibernate.xml,
/WEB-INF/modules/coreConfiguration/applicationContext-hibernate.xml,
/WEB-INF/modules/coreConfiguration/applicationContext-service.xml
</
param-value
>
</
context-param
>
则可以正常取到上面的实例。

本文探讨了在Struts和Spring框架集成时遇到的问题。具体表现为,在struts-config.xml中配置Spring插件加载多个XML配置文件后,无法通过WebApplicationContext获取特定的服务Bean实例。然而,相同配置放在web.xml中时,则能正常工作。
7787

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



