@Transactional with static method

前端 未结 3 1491
长情又很酷
长情又很酷 2020-12-19 08:07

Why cant we use @Transactional for static methods to manage the transactions in my spring Project ?

@Transactional works well for non stati

3条回答
  •  甜味超标
    2020-12-19 08:49

    If you're using AspectJ, here's a simple, albeit ugly, workaround:

    public static void doWhatever(final String param) {
        new Runnable() {
            @Transactional
            public void run() {
                // do whatever in transaction...
            }
        }.run();
    }
    

提交回复
热议问题