3

How can I debug the transactions in my spring boot application ?

Is there a way to see how method calls get grouped in a transaction context or another ?

screab
  • 169
  • 3
  • 14

1 Answers1

0

You have asked 2 broad questions here.

1. How to debug a transaction (assuming from your post title, you are looking for logging)

The simplest way to achieve is to use the bundled java.util.logging.Logger in SpringBoot.

Below code snippet should tell you how:

public class EmojiController {

    private final static Logger logger = Logger
            .getLogger(EmojiController.class.getName()); 

    public ModelAndView getEmoji() {
        logger.info("emoji: " + emojiId + " lookup initiated");
        ---do something---
}

By default, If you use the ‘Starters’, Logback will be used for logging. Appropriate Logback routing is also included to ensure that dependent libraries that use Java Util Logging, Commons Logging, Log4J or SLF4J will all work correctly.

2. Grouping the method calls related to one transaction:

This is a very wide topic and has even wider application when asked in the context of distributed application architecture like, micro-services. The point is, how do you relate various log entries with each other to group them for a wholistic view.

The solution for that lies in the concept called Distributed Tracing. You can read in detail about that in this wonderful post from Josh Long.

More detailed documentation on the discussed technologies can be found here -

It should help you achieve what you want but in case you have more questions on their usage, please raise another question.

--- EDIT ---

There's a section about Logging in the Spring Reference.

It shows how to configure different logging frameworks, among them log4j

In your case the last line of the config would be:

log4j.logger.org.springframework.transaction=DEBUG

Ashwin Gupta
  • 920
  • 1
  • 11
  • 17
  • 2
    1. You are mentioning logging but I am interested in what spring framework can log related to how it handles transactions or better said how it handles methods annotated with @Transactional. I would also be interested in how I can get insights into spring's inner workings by the use of a debugger ( what classes to look for, where to set break points, if this is really doable, etc ) – screab Mar 10 '17 at 12:08
  • 2. I don't have a distributed application so you answer doesn't apply. I want to know if there is a way (for example turning on the logging for some spring component) to see how spring handles/groups @Transactional annotated methods. – screab Mar 10 '17 at 12:11
  • I had suggest you be more detailed and specific in the original question then. I believe this post shall answer it for you wrt what happens in background. - http://stackoverflow.com/questions/1099025/spring-transactional-what-happens-in-background to give you some idea of its internal and methods to debug – Ashwin Gupta Mar 10 '17 at 12:21
  • I've edited my answer to cover how to debug transactional methods in particular. I hope it helps – Ashwin Gupta Mar 10 '17 at 12:23