如何查看由Spring隐藏的嵌套异常跟踪?

时间:2012-11-02 13:11:16

标签: eclipse spring debugging exception output

当我在Eclipse中调试Spring应用程序时,我得到了很长的异常链。例如,我有

Error creating bean with name '...' defined in file [...Tester.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property '...' threw exception; nested exception is java.lang.IllegalArgumentException: ...

等等。 Spring中有多个异常堆栈,这是无趣的。它应该是我在下面某处的例外情况,但Spring并未显示它们。

我无法像往常一样点击异常并导航到问题所在地。

如何说Spring输出所有异常?

更新

以下是完整输出。可以看到IllegalArgumentException发生的地方可能已被截断。

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybean' defined in file [D:\mypath\myconfig.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'myproperty' threw exception; nested exception is java.lang.IllegalArgumentException: my exception message
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.(FileSystemXmlApplicationContext.java:84)
    at springtests.SpringRunner.main(SpringRunner.java:8)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'target.partner' threw exception; nested exception is java.lang.IllegalArgumentException: Illegal frame length 1 in explicit constructor
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
    ... 13 more

1 个答案:

答案 0 :(得分:1)

因为可能存在多个异常,所以需要捕获PropertyBatchUpdateException并调用getPropertyAccessExceptions()来检查特定异常的堆栈跟踪。

修改

其实我不太确定这里发生了什么

以下是PropertyBatchUpdateException的{​​{1}}方法:

printStackTrace

它应该包括嵌套的堆栈跟踪。您使用的是最新版本的Spring吗?

编辑:

我能建议的最好的方法是在调试模式下运行,然后在public void printStackTrace(PrintWriter pw) { synchronized (pw) { pw.println(getClass().getName() + "; nested PropertyAccessException details (" + getExceptionCount() + ") are:"); for (int i = 0; i < this.propertyAccessExceptions.length; i++) { pw.println("PropertyAccessException " + (i + 1) + ":"); this.propertyAccessExceptions[i].printStackTrace(pw); } } } 放置一个断点,看看发生了什么。