开发者社区> 问答> 正文

SSH Struts2 中获取service失效

<bean id="gradeDao_msi" class="com.msi.dao.impl.GradeDaoImpl">
  <property name="sessionFactory">
   <ref local="sessionFactory" />
  </property>
 </bean>

<bean id="gradeService" class="com.msi.service.impl.GradeServiceImpl">
  <property name="gradeService_msi">
   <ref local="gradeDao_msi" />
  </property>
 </bean>

 <bean name="GradeAction" id="GradeAction" class="com.msi.action.GradeAction"> 
  <property name="service"> 
   <ref bean="gradeService" /> 
  </property> 
 </bean>
-------------------------------------

Action 中
GradeService service;
public void setService(GradeService service) {
  this.service = service;
 }

然後使用service 調用GradeService中的方法,總是提示java.lang.NullPointerException
請教如何解決

展开
收起
a123456678 2016-03-17 09:31:09 1748 0
1 条回答
写回答
取消 提交回答
  • 出现这个问题最大的可能都是误用struts2-spring插件导致, 你这样配置没错,只是struts2取action时候不从你这个springcontext中去,而是自己新建的action实例,所以导致你的注入娶不到,最简单的做法是照抄struts2提供的集成例子,

    2019-07-17 19:04:29
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《基于 Service Worker 实现在线代理》 立即下载
WEB SERVICE EFFICENCY 立即下载
“移”网打尽—— Mobile Network as a Service 网络即服务 立即下载