我们的春季应用是一个服务层,附加说明的是@Transactional。 我们需要制定一些交易方法前后的守则,理由如下:
- We need to synchronize access to the method based on a key. The thread needs to block before the start of the transaction.
- We need to post a message on a queue if the transaction succeeds.
选择似乎是:
- Create a class with similar methods to the service that can run the @Transactional method in a synchronized block and check for the return then post the message (would need a separate class due to AOP proxy problem). Services calling services, not nice, feels like a work-around.
- Write an aspect to wrap around the @Transactional AOP which can do the synchronization and message posting. Might work but would rather avoid AOP.
- Move the transaction down to the domain layer. Not desirable or possibly even feasible with the current implementation due to the way domain methods are reused in different workflows.
- Code the transaction by hand in the service method and scrap @Transactional.
我想这是一个相当共同的要求。 也许我没有选择5,这是显而易见的。