web.xml配置如下:
SystemAction.java代码如下:
| 代码: |
..... <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>SpringContextServlet</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> ..... |
SystemAction.java代码如下:
| 代码: |
| import javax.servlet.ServletContext; import org.apache.struts.action.Action; import org.apache.struts.action.ActionServlet; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import com.sse.ofmis.service.ISystemService; public abstract class SystemAction extends Action { private ISystemService systemService; public void setServlet(ActionServlet actionServlet) { super.setServlet(actionServlet); ServletContext servletContext = actionServlet.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); this.systemService = (ISystemService) wac.getBean("mySystemService"); } protected ISystemService getSystemService() { return systemService; } } |
本文介绍了一个将Struts与Spring框架集成的例子,通过web.xml配置和SystemAction类实现Spring管理业务服务。
483

被折叠的 条评论
为什么被折叠?



