铁血四骑士在线观看:在使用Spring时不使用注入方式获取bean

来源:百度文库 编辑:九乡新闻网 时间:2024/10/06 02:00:52
项目中使用了ssi的结构,在大多数的struts配置文件中都是用class="xxxxBean",然后在spring的配置文件中配置这个bean 
   
   InitCart.jsp
  
 但在有的action中就一个简单的方法,并不想写bean,但又需要用到spring控制,怎么办?可以直接在代码中用如下语句获得需要的bean ApplicationContext ctx = WebApplicationContextUtils
      .getWebApplicationContext(ServletActionContext
        .getServletContext());
    DxmScCarViewService carViewService = (DxmScCarViewService) ctx
      .getBean("bean的名称");