查看全文
Spring Framework从诞生之日起,受到了越来越多的关注。最近,新的开源项目大多支持Spring Framework。国内目前也有专门的网站(http://spring.jactiongroup.net/)。那它为什么如此受欢迎呢?
我想最重要的是,EJB让每个人都痛恨。要编写一个EJB,需要写LocalHome, RemoteHome, Bean, LocalInterface, RemoteInterface,需要一个标准描述符,一个特殊厂商描述符(Weblogic、WebSphere都不一样),如果是Entity Bean,还需要Mapping文件。如此之多,实在麻烦。但EJB最重要的是解决Transaction问题,没有Spring之前,没有其他方法能够描述式的解决它。每个人、每个公司为了解决Transaction的问题,编程的写法都不一样,百花齐放。于是,在最需要它的时候,Spring出现了。
查看全文http://struts.sourceforge.net/struts-spring/
不错的struts插件,可以让你用spring的Ioc容器来管理你的Action,以及为action注入需要的对象。
配置使用也比较简单。目前新的版本spring已经集成了这个插件,不用下载安装就可以使用。spring的apidoc里还有相关的说明。
在struts-config.xml中加入插件的配置:
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
在struts-config.xml中配置你的action的type为统一的代理
<action path="/logon"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="success" path="/logon.jsp"/>
</action>
在applicationContext.xml文件中,配置bean和你的action,注意配置action是,action的名字必须使用name属性指定。而普通的bean也可以用id指定。
<bean id="userDatabase" class="org.apache.struts.webapp.example.memory.MemoryUserDatabase" destroy-method="close" />
<bean name="/logon" class="org.apache.struts.webapp.example.LogonAction">
<property name="userDatabase"><ref bean="userDatabase" /></property>
</bean>
看这样你的action实例将由spring的容器来生成,所以就可以完成userDatabase对象的注入了。
这里你不要试图配置用动态代理实现action的方法的拦截,那可能会有问题的,这可能有动态代理实现机制决定的。在这个连接的网站上有一个专门的struts插件可以实现action方法的拦截。
http://struts.sourceforge.net/saif/index.html






