美文网首页
SqlSession was not registered fo

SqlSession was not registered fo

作者: 日落_3d9f | 来源:发表于2022-09-02 17:43 被阅读0次

    编写测试代码:

        @Test
        public void callBack() throws InterruptedException {
            ExecutorService executorService = Executors.newFixedThreadPool(100);
            for (int i = 0; i < 100; i++) {
                executorService.execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            payBack();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        }
    
    
        public void payBack()  {
            String tradeNo = "202259607180675101";
            //log.info("--------"+tradeNo+"--------");
            //通过tradeNo查询订单状态。交易单号
            ProductOrderDO productOrderDO = productOrderService.queryProductOrderState(tradeNo);
            if(productOrderDO == null) {
                log.error("--------fail--------------------"); ;
            }
            log.info("--------"+tradeNo+"--------");
            String orderState = productOrderDO.getState();
            //sleep(1000l);
            log.info("--------"+orderState+"--------");
        }
    

    发现SQL根本没有执行,出现报错

     [“SqlSession[xxx] was not registered for synchronization because synchronization is not active
    

    原因是Sqlsession未注册同步,同步注册未激活,JDBC connection不能被Spring所托管,,,callBack方法加事务注解@Transactional就可以了

    相关文章

      网友评论

          本文标题:SqlSession was not registered fo

          本文链接:https://www.haomeiwen.com/subject/igkynrtx.html