Struts与Spring整合:bbp project
来源:互联网 发布:windows 10 for phone 编辑:程序博客网 时间:2024/06/12 01:04
(注:在我的opensource里,还struts与spring的三种整合方式,都很好,是我转载别人的,在看他们俩整合时,不要忘记参看。)
our project user spring and structs method summerize:
1、首先,我们在struts-config.xml文件中,存在以下语句,目的是把struts动作委托给一个类来处理:
<action-mappings> (注:type的书写是正常的)
<action path="/search/user" parameter="type" type="com.innov8tion.action.UserAction" scope="request">
<forward name="user" path="/search/user.jsp" redirect="false" />
</action>
</action-mappings>
<controller processorClass="com.innov8tion.action.ServiceAutowireRequestProcessor" /> //重要
2、写ServiceAutowireRequestProcessor类:
import org.apache.struts.action.RequestProcessor;
public class ServiceAutowireRequestProcessor extends RequestProcessor {
/**
* Override the base class method to return the autowireService action.
*/
protected Action processActionCreate(HttpServletRequest request,
HttpServletResponse response, ActionMapping mapping)
throws IOException {
Action action = super.processActionCreate(request, response, mapping); //用Struts创建默认的action
autowireService(action); //用spring注入action中的属性
return action;
}
private void autowireService(Action action) {
ServiceLocator.getInstance(action).autowireService(action); //ServiceLocator是我们自己写的类。
}
}
public final class ServiceLocator {
private static ServiceLocator instance = null;
private ApplicationContext context = null;
/**
* Create a new ServiceLocator Instance.
*/
private ServiceLocator(ApplicationContext context) {
this.context = context;
}
/**
* @return ServiceLocator Instance
*/
public static ServiceLocator getInstance(Action action) {
ServletContext servletContext = action.getServlet().getServletContext();
if(instance == null){
ApplicationContext ctx = WebApplicationContextUtils.
getRequiredWebApplicationContext(servletContext);
instance = new ServiceLocator(ctx);
}
return instance;
}
public void autowireService(Object bean) {
((AbstractApplicationContext) context).getBeanFactory()
.autowireBeanProperties(bean,
AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
}
}
总结:
1. 在ServiceLocator类中的autowireService方法,目的是使用spring IOC自动绑定功能来注入action中的属性。
2. 在ServiceAutowireRequestProcessor 类中的processActionCreate方法,我觉得其不仅让struts与spring耦合很小,而且在spring配置文件中,省写了struts的action的配置。
- Struts与Spring整合:bbp project
- 整合Struts 与Spring
- 整合Struts 与Spring
- 整合Struts 与Spring
- struts与spring整合
- spring与struts整合
- Spring与Struts整合
- Spring与Struts整合
- Spring与struts整合
- Spring与Struts整合
- spring 与struts 整合
- struts与spring整合
- Spring与Struts整合
- spring与struts整合
- Spring与Struts如何整合
- Struts与Spring的整合
- Spring 与 struts 2 整合
- struts与spring的整合
- Yahoo!网站性能最佳体验的34条黄金守则——JavaScript和CSS
- Yahoo!网站性能最佳体验的34条黄金守则——图片、Coockie与移动应用
- freemarker学习手册二
- Windows环境下配置Apache 2.2.x + SSL
- Security(签名证书) for Mobile
- Struts与Spring整合:bbp project
- 求100或1000个随机0到1的平均数看看哪个更接近0.5
- Windows环境下Apache的安装与虚拟主机, 虚拟目录的配置
- 读取带有标记文件的函数接口。
- Repeater 中CheckBox的相关操作
- 测试用例执行态度
- 项目概要设计书一般设计方法 经典转载
- Unable to find an Ant file to run
- 做软件项目就是一种学习