@Transactional和JerseyTest在Linux或Mac上出现问题,但不在Windows上

我们使用grizzly2进行jerseytesting,对嘲笑的REST资源进行验收testing。 在我的Windows机器上一切都很好。 但是另一位使用Mac的开发人员却遇到了与我们的Jenkins(在Linux上)相同的错误:

INFO: Creating Grizzly2 Web Container configured at the base URI http://localhost:9998/ 02.08.2012 09:46:36 org.glassfish.grizzly.http.server.HttpServer start SEVERE: Failed to start listener [NetworkListener{name='grizzly', host='localhost', port=9998, secure=false}] : java.net.BindException: Address already in use 

很明显,我们检查,情况并非如此:没有其他进程正在使用9998 ..

我一直在跟踪问题到一个单一的testing,即使用@Transactional结合扩展JerseyTest:

 @ContextConfiguration({ "classpath:context-test.xml" }) @RunWith(SpringJUnit4ClassRunner.class) @Transactional @TransactionConfiguration(defaultRollback = true) public class TestPage extends JerseyTest { public TestPage() throws Exception { super("", "", "path.to.package"); } // init database to be rolled back after test // ... // test that calls a controller requiring database access and then sends a request to a mock REST resource. // ... } 

所以,这里的问题是:为什么不在Windows上? 而使用@Transactional有什么问题。

edit2看来@Transactional正在创build一个代理,这可能是一个问题..?! 看这里

我遇到了类似的问题,请确保您不覆盖TestPage测试中的tearDown()方法。 如果你有东西要拆掉,用另一个方法customTearDown()来做,并用@After注解它。

JerseyTest也使用相同的方法名称tearDown(),如果我们覆盖它,容器永远不会关闭。