views:

1746

answers:

3

I am trying to use Spring for the first time in an application. The general issue that comes up again and again is that I have no idea how to debug Spring. The framework is so configuration heavy that traditional code debugging seems fruitless. Short of turning on the debugging level logs (which are lacking) and scanning through I have no real idea how to go about troubleshooting.

Anyone have any general tips or tools for assisting Spring debugging?

A: 

I generally just use the java debugger in eclipse - it works fine on most classes. Some classes are wrapped at compile/runtime by bytecode changes - for these you generally cannot put breakpoints in methods, however you can set a breakpoint at method entry.

If you have a very specific situation you maybe should elaborate a bit in your question.

I'm generally also ok with the logging levels - what do you think is wrong with them?

Simon Groenewolt
Well I was trying to keep this generic, but for latest issue I am trying to debug a null entity manager. The logging doesn't give me any useful information, or at least not anything that sticks out at me and you can't really set breakpoints on annotations.
James McMahon
A: 

I don't think Spring debugging should be any different to any other debugging scenario.

What aspects of Spring are you using ? If you're using dependency injection properly, then I wouldn't anticipate any problems.

However if you're dynamically resolving beans via their name (at runtime, using ApplicationContext.getBean()) then I can see that's going to cause you problems anticipating flow of control etc., and would suggest that you revisit your IoC.

EDIT: It's quite useful to have the Spring source code available. It's well put together and quite readable, and therefore possibly of use when debugging.

Brian Agnew
I am using spring MVC with dependency injection. Using it "properly" is the problem. How do you about debugging dependency injection?
James McMahon
I would a) use constructor dependency injections b) instantiate your framework and then inspect what you've injected into your bean constructors. You're debugging the program in a static sense - i.e. how has it been constructed ?
Brian Agnew
+2  A: 

If you're using Eclipse, then get hold of the Spring IDE (or better yet, the free SpringSource Tool Suite). This will provide code-completion, bean visualisation, and hot-linking to your config files.

toolkit
Thanks, that looks interesting.
James McMahon
I don't know whether the license was changed since this answer was first provided, however the SpringSource Tool Suite license allows free usage only for "non-production purposes of Licensee's internal business operations, development, evaluation, and education".
Brian
I just looked at one of the original posts from Spring from May 2009, which announced that STS would be free for *all* development purposes. So, I don't know how the development and production phases differ in their minds.
Brian