打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
在使用Spring时不使用注入方式获取bean
项目中使用了ssi的结构,在大多数的struts配置文件中都是用class="xxxxBean",然后在spring的配置文件中配置这个bean
 
<action name="addCar" class="caropBean" method="initCartAction">
   <!-- 
   <result name="result">InitCart.jsp</result>
    -->
   <result name="success">InitCart.jsp</result>
  </action>
 
但在有的action中就一个简单的方法,并不想写bean,但又需要用到spring控制,怎么办?
可以直接在代码中用如下语句获得需要的bean
 
ApplicationContext ctx = WebApplicationContextUtils
      .getWebApplicationContext(ServletActionContext
        .getServletContext());
    DxmScCarViewService carViewService = (DxmScCarViewService) ctx
      .getBean("bean的名称");
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Spring Core
Struts调用Spring服务类的三种方法
spring整合MyBatis思路
spring面试题
struts2和spring的两种整合方式
Spring AOP框架
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服