2012-04-25 66 views
1

在使用Maven對Spring應用程序進行單元測試後完成構建時出現問題。我注意到mvn安裝沒有完成,並且在運行所有單元測試後它似乎掛起。從CMD行,如果我跑mvn install我得到的測試來完成,但構建掛起Maven在運行Spring JUnit測試後掛起

Results : 

Tests run: 34, Failures: 0, Errors: 0, Skipped: 0 

14:20:15,588 [Thread-3] INFO GenericApplicationContext - Closing [email protected]a3b24: startup date [Wed Apr 25 14:20:08 EDT 2012]; root of context hierarchy 
14:20:15,589 [Thread-3] INFO DefaultListableBeanFactory - Destroying singletons in org.s[email protected]16c163f: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,sysModel,alarmList,resourcePool,sysParams,stationHelper,commandTracker,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 
14:20:15,595 [Thread-7] INFO GenericApplicationContext - Closing [email protected]577c: startup date [Wed Apr 25 14:20:10 EDT 2012]; root of context hierarchy 
14:20:15,596 [Thread-7] INFO DefaultListableBeanFactory - Destroying singletons in org.s[email protected]10952e8: defining beans [alarmDao,purgeDao,xactionDao,dataSource,sysModel,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy 

這就是它的結束。兩個線程運行,不知道我在那裏做了什麼。無論如何,爲了排除故障,我刪除了所有測試,並讓程序完全構建。如果我運行mvn install -DskipTests,我會完成它。最後,我添加了一個基本上是system.out.println(「hello world」)的JUnit測試。我可以通過註釋掉JUnit註釋「@RunWith(SpringJUnit4ClassRunner.class)」來讓安裝運行測試並完成安裝。我使用的是Spring 3.1.0.RELEASE。

構建的這個問題來自Windows7上的我的開發機器,但是基於Linux(Ubuntu 11.10)。 Hudson CI服務器使用相同的SVN存儲庫成功地在同一個項目上運行Maven安裝,每小時構建一次。

回答

1

可能是你的一個Spring bean產生了一個線程。使用jconsole連接到卡住的進程並查看掛起的內容。您可以通過在有問題的bean上使用@PreDestroy來解決此問題,以便在關閉時取消線程。

+1

是的,檢查你是否正在做任何手動線程創建,或者如果你使用@Asynchronous或者Spring的定時器/執行程序代碼。 – sdouglass 2012-04-25 19:12:57

0

在Spring應用程序上下文關閉過程中,線程之間似乎存在一些爭用。您可以嘗試啓動Spring框架的日誌記錄來調試級別,以查看爭用的位置,如果可以的話,將其消除。

如果它在應用上下文中看起來不是問題,那麼另一個選擇是調整插件配置。 surefire插件用於執行測試,並且它具有在多個線程中運行測試的選項。首先運行mvn -X以查看線程選項(parallel,threadCount,perCoreThreadCount等)的值。調整surefire插件配置(執行ID爲default-test)以確保只有一個線程正在執行,並查看您是否可以在您的Windows 7機器上運行install

一旦你在Windows中工作:你當前的surefire配置(可能是超級POM提供的默認配置)在你的CI環境中工作正常。所以我會創建一個profile, activated if running on the Windows 7 environment,並將標識的surefire插件配置移動到配置文件中。