Spring与Struts集成方式三
在集成方式一和二中我们是在web.xml中加入配置代码:
?
而在applicationContext-actions.xml中配置
?
?
本文就是根据spring Framwork开发手册对上述做一些改进,改进后的配置只需要修改struts-config.xml即可。
1、对于之前在web.xml中加入的代码,我们在struts-config.xml使用插件来实现
如:在struts配置文件中加入
?
?
现在要集成spring与struts要怎么做呢。
1、创建web项目,加入struts的所有包和配置文件。可以创建LoginAction测试是否成功。
2、加入spring的所有包,并在src目录创建applicationContext-beans.xml和applicationContext-actions.xml文件
其中applicationContext-beans.xml专门用于注入daoBean,而applicationContext-actions.xml用于写一些与struts-config.xml相对应的action注入。
3、在struts-config.xml中加入plugin和controller即上面所讲的。
4、在applicationContext-actions.xml加入action bean的name必须与struts-config.xml中的path一样
好了。我们把改进后的完整代码贴出来:
web.xml
?applicationContext-actions.xml
?
applicationContext-beans.xml
?最后是struts-config.xml
?
注意看我们的
?
中省略了type也是可以的,因为现在由spring来注入action了。。
?
因为准备做ssh的集成,所以项目名称改成了SpringStrutsHibernate,不过这里面只包括了spring+struts的集成,实际就是对集成方式二的改进。