启动spring的两个典型方式

本文介绍了两种在Web应用中启动Spring框架的方法:一种是在web.xml中配置ContextLoaderListener监听器,另一种是在struts-config.xml中使用ContextLoaderPlugIn插件。通过这两种方式可以实现Spring容器的初始化。

方法1,在web.xml中启动时在文件最前面添加下面几行代码即可:
<!-- 启动Spring  -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>

方法2,在struts-config.xml中用插件方式启动:
在applicationContext.xml中修改:
<bean id="userBiz" class="com.svse.ssh.web.action.LoginAction">
<property name="userBiz" ref="userInfoBiz"></property>
</bean>
为(或直接添加):
<bean name="/login" class="com.svse.ssh.web.action.LoginAction">
<property name="userBiz" ref="userInfoBiz"></property>
</bean>
在struts-config.xml中修改action:
<action
input="/form/register.jsp"
name="addUserForm"
path="/addUser"
scope="request"
type="com.svse.ssh.web.action.AddUserAction">
<forward name="failure" path="/form/failure.jsp" />
<forward name="success" path="/form/success.jsp" />
</action>
然后在struts-config.xml中添加下面几行代码:
<!-- 启动Spring -->
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml"/>
</plug-in>

以上面两种为基础最后在struts-config.xml中添加下面代码:
<!-- 定义一个控制器,通过这个控制器自动将请求转发到Spring容器 -->
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值