我们使用带有 grizzly2 的 jersey 测试来针对模拟的 REST 资源运行验收测试。在我的 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..
我一直在将问题跟踪到单个测试,即使用 @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 正在创建代理,这可能是个问题..?!看这里