1

在使用 Maven 对 Spring 应用程序进行单元测试后完成构建时出现问题。我注意到 mvn install 没有完成,并且在运行所有单元测试后它似乎挂起。如果我运行,则从 cmd 行mvn install完成测试,但构建挂起

Results :

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

14:20:15,588 [Thread-3] INFO  GenericApplicationContext  - Closing org.springframework.context.support.GenericApplicationContext@10a3b24: 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.springframework.beans.factory.support.DefaultListableBeanFactory@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 org.springframework.context.support.GenericApplicationContext@c5577c: 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.springframework.beans.factory.support.DefaultListableBeanFactory@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 安装以进行每小时构建。

4

2 回答 2

1

可能您的一个 Spring bean 正在生成一个线程。使用 jconsole 连接到卡住的进程并查看挂起的内容。您可以通过在有问题的 bean 上使用 @PreDestroy 以在关闭时取消线程来修复它。

于 2012-04-25T18:42:10.797 回答
0

在 Spring 应用程序上下文关闭期间,线程之间似乎存在一些争用。您可以尝试将 Spring 框架的日志记录设置为调试级别,以查看争用的位置,并尽可能消除它。

如果在应用程序上下文中似乎没有问题,另一种选择是调整插件配置。该surefire插件用于执行测试,它具有在多个线程中运行测试的选项。首先运行 mvn with-X查看线程选项(parallel、threadCount、perCoreThreadCount 等)使用了哪些值。调整 surefire 插件配置(执行 ID 为default-test)以确保只有一个线程正在执行,并查看您是否可以install在 Windows 7 机器上运行。

一旦你让它在 Windows 中运行:你当前的 surefire 配置(可能是超级 POM 提供的默认配置)在你的 CI 环境中运行良好。因此,我将创建一个配置文件,如果在 Windows 7 环境中运行则激活,并将确定的 Surefire 插件配置移动到配置文件中。

于 2012-04-25T19:25:13.727 回答