070615 struts中spring载入小结

本文介绍了如何在Struts框架中整合Spring框架进行MVC架构的配置。详细讲解了通过Struts-config.xml设置ContextLoaderPlugIn插件来指定Spring配置文件的位置,并提供了多种配置示例,包括将配置文件放置于WEB-INF目录下的方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果是在struts-config.xml中直接写为 <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"/>  ,则是默认配置文件为在WEB-INF下的action-servlet.xml文件,可在action-servlet.xml中再截入各个action bean的配置,如<import resource="modules/spring-config-login.xml"/>等。
另外service的配置和applicationContext.xml或sping相关的数据库文件,可自己建立一个目录,然后在web.xml中加载    <context-param>
        <param-name>contextConfigLocation</param-name> 
        <param-value>classpath*:spring/*.xml</param-value>
    </context-param>  
这样将web层和service层的配置分开摆放,看起来比较清晰。具体可参考springside的example

另一方法是struts-config中直接写 <plug-in  className="org.springframework.web.struts.ContextLoaderPlugIn"> 
<set-property property="contextConfigLocation"  value="classpath*:spring/*.xml"/> 
</plug-in>
这样将所有的配置文件直接放在spring目录下

或小型应用可简单写成最直接的<plug-in className= "org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property= "contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>


不过多句提醒下记得不要漏了web.xml中还应有    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
 </listener> 

struts-config.xml中还应有:
 <controller>
  <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
 </controller>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值