Is there a friendlier view of BeanCreationException / ApplicationContext load problems

Brian Deacon :

Diagnosing spring wiring problems usually involves digging through very long messages in the stack trace that look like:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'foo' defined in class path resource [blah/blah/Foo.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [blah.blah.Foo]: Factory method 'foo' threw exception; nested exception is ... [five more of these because your wiring is Byzantine] nested exception is [your real problem]

Are there any tools/techniques to make seeing those errors easier? The silly pain point is mostly that the message is one very long line that scrolls way off to the right in the IDE's console (in this case IntelliJ) and the punch line is always at the end.

I'm imagining possibly a plugin for friendlier stack trace display, or maybe something with specific spring smarts.

Gabriel Robaina :

After some research, and the suggestion of @klorand, I came across three ways of improving the way IntelliJ display stack traces:

  1. You can click on the "use soft wraps" icon on the right side of the window. This will prevent horizontal scrolling, making any information that exceeds the window width to be displayed on a new line.

    soft wraps

  2. There is a configuration on IntelliJ called console folding. You can specify filters for IntelliJ to hide certain packages from the stack trace. Simply click any line of the stack on the "Debug" window and select "Fold Lines Like This". This will open up a configuration window similar to this one:

    Fold Lines

    In this example, all console lines that contains at sun.reflect will be folded. I have been constantly adding new filters, and using this configuration to make my stack traces vertically smaller.

  3. You can use Logback to customize the way logs are shown in the console. I used the following configuration on my logback.xml file to truncate all warning and error messages logged on console. With format configuration you can specify min/max width and justification. I have hidden package and method information, so that only the core message would be shown, but you can also specify the limit number of characters to be shown, or even customize a custom converter.

Before:

Before trimming

After:

After trimming

Finally

Combining these three configuration settings will help you make console messages vertically or horizontally smaller, and take more control over how log messages are shown or console, or saved to a file.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related