struts2 + spring 整合的问题

    技术2022-05-11  21

    最近我们开的项目使用 struts2+spring 的时候,在遇到提交页面的遇到 dao 为空(已经在 spring 里注入), 大概异常见下:          java.lang.NullPointerException com.richser.web.action.ServiceAction.save(ServiceAction.java:55) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) 也就是说: dao 没有实例化了 解决办法: 配置 spring 的事务          <!-- AspectJ 方式 定义 AOP -->          <aop:config proxy-target-class="true">          <aop:pointcut id="contractService"              expression="execution(* com.richserc.contract.service..*ContractTypeService.*(..))"/>          <aop:pointcut id="contractWebService"              expression="execution(* com.richserc.contract.web..*ContractTypeAction.*(..))"/>                      <aop:advisor advice-ref="txAdvice" pointcut-ref="contractService" />          <aop:advisor advice-ref="txAdvice" pointcut-ref="contractWebService" />     </aop:config>          <!-- 基本事务定义 , 使用 transactionManager 作事务管理          <tx:advice id="txAdvice" transaction-manager="transactionManager">                    <tx:attributes>             <tx:method name="save*"/>              <tx:method name="update*"/>              <tx:method name="remove*"/>             <tx:method name="*" read-only="true"/>                     </tx:attributes>          </tx:advice> 建议和 http://blog.csdn.net/xray_gu/archive/2007/06/18/1656062.aspx 一并参考  

    最新回复(0)