<!-- 配置事务特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes> <tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="deploy*" propagation="REQUIRED" />
<tx:method name="submit*" propagation="REQUIRED" />
<tx:method name="get*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="daoMethods"
expression="execution(* net.hlj.kj.dao.*.*.*(..))" />
<!-- 定义了将采用何种拦截操作,这里引用到 txAdvice -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods" />
</aop:config>
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
action 
public void activeUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception { long id = UtilTool.str2Long(request.getParameter("id"));
  TdUser tu = userService.getUserById(id);
if (tu.getState() == 0) {// 判断是否激活
try { bouns(tu.getId(), tu.getSuperid(), 1);
 
TdUser agent = userService.getUserById(tu.getAgentid());
agent.setMb(5d); 
userService.update(agent);
  //激活账户
userService.activeUser(id);
//购买股票
    userService.buyStock(tu);
      
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
response.sendRedirect("doUser.do?method=getUserListByAgent");
}
在这地方 userService.buyStock(tu),这里面有空指针异常,但是事务去不回滚,怎么回事呀?

解决方案 »

  1.   

    目录结构是这样的:
    net.hlj.service.user.UserService
    net.hlj.service.user.UserServiceImpl
    net.hlj.service.sys.SysServiceImpl
    net.hlj.service.sys.SysServiceImpl
    net.hlj.dao.user.UserDao
    net.hlj.action.user.UserAction
    net.hlj.action.sys.SystemAction
      

  2.   

    去掉catch(Exception)从句,〈tx:method〉中添加rollbackFor="Exception"
      

  3.   

    public void buyStock(TdUser tu  ) {
    TdStock tdStock = stockService.getStock(UtilTool.getDateYMD()); TdBuy tdBuy = new TdBuy();
    tdBuy.setUserid(tu.getId());
    tdBuy.setBuyprice(tdStock.getCurprice());
    long buynumber = new Double(70 / tdStock.getCurprice()).longValue();
    tdBuy.setBuynumber(buynumber);
    stockService.buyStock(tdBuy);
    // 剩余的钱给存到账户上

    tu.setGamecoin(70 - buynumber * tdStock.getCurprice());// 
     update(tu); }
    这方法是这样的!我没有用try catch
    我按照楼下的说了,还是不行呀。