struts2出来的时候,说是基于webwork核心,而不是由struts1升级而来,一直好奇struts蛮好的一个东东为啥不要了而要从别人那儿copy呢。终于有机会和时间学习了一把webwork......
不过webwork说明里还有IoC的功能,还没来得及看,而且webwork官方也推荐用spring做IoC容器,就先将这两个整合了一下。
其实具体实现起来倒是很简单。
在webwork.properties文件中声明对象使用spring来生成:
webwork.objectFactory=spring webwork.objectFactory.spring.autoWire=true然后在web.xml里加一个spring监听器<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>最后在xwork.xml里定义action的时候让action的class属性指向spring定义的bean即可:xwork.xml:<action name="login" class="loginBean"> <result>welcome.jsp</result> </action>spring's applicationContext.xml<bean id="loginBean" class="com.qtx.test.webwork.action.LoginAction"> <property......> </bean>