2012-04-25 67 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插件配置移动到配置文件中。