2012-11-02 41 views
0

當我在Eclipse中調試Spring應用程序時,我得到很長的異常鏈。例如,我有如何查看由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沒有顯示它們。

而且我無法點擊進入異常並像平常一樣導航到問題位置。

How to say Spring輸出所有異常?

UPDATE

以下是完整輸出。人們可以看到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 
+0

它不會截斷異常。這就是你在嵌套異常時所得到的結果。 – artbristol

+0

是的,這些是嵌套異常。如何讓它們全部顯示? – Dims

+0

他們*都*顯示。但是讀取堆棧跟蹤可能會令人困惑。看看http://docs.oracle.com/javase/6/docs/api/java/lang/Throwable.html#printStackTrace%28%29 – artbristol

回答

1

因爲有潛在的多個異常,就需要抓住PropertyBatchUpdateException並調用getPropertyAccessExceptions()檢查特定異常的堆棧跟蹤。

編輯

其實我不太清楚是怎麼回事

這裏是PropertyBatchUpdateExceptionprintStackTrace方法:

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); 
      } 
     } 
    } 

應包括嵌套的堆棧跟蹤。你使用的是最新版本的Spring嗎?

編輯:

我可以建議最好是在調試模式下運行,然後把一個斷點AbstractAutowireCapableBeanFactory.java:1361,看看發生了什麼事情。

+0

可能是有一些春天的配置,可能會使它只是顯示所有它? – Dims

+0

你把Spring的日誌配置設置爲DEBUG嗎? – artbristol

+0

我不知道。我有'log4j.rootLogger = DEBUG,A1'在classpath中有自己的'log4.properties'文件。 – Dims