Glassfish Embedded 容器有什么问题?
这是我的 pom.xml
(其中一部分):
[...]
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-embedded-glassfish</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
[...]
这是测试:
public class FooTest extends JerseyTest {
public FooTest() throws Exception {
super("com.XXX");
}
@Before
public void setUp() throws Exception {
}
@Test
public void shouldWork() throws Exception {
}
}
这是我在日志中得到的内容:
com.sun.jersey.test.framework.spi.container.TestContainerException: org.glassfish.embed.EmbeddedException: You must start the server before calling this API method: EmbeddedDeployer.EmbeddedDeployer Constructor.
at com.sun.jersey.test.framework.spi.container.embedded.glassfish.EmbeddedGlassFishTestContainerFactory$EmbeddedGlassFishTestContainer.stop(EmbeddedGlassFishTestContainerFactory.java:154)
at com.sun.jersey.test.framework.JerseyTest.tearDown(JerseyTest.java:312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
当我从中删除 setUp()
方法时班级一切正常。这是怎么回事?
This is my pom.xml
(part of it):
[...]
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-embedded-glassfish</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
[...]
This is the test:
public class FooTest extends JerseyTest {
public FooTest() throws Exception {
super("com.XXX");
}
@Before
public void setUp() throws Exception {
}
@Test
public void shouldWork() throws Exception {
}
}
This is what I'm getting in the log:
com.sun.jersey.test.framework.spi.container.TestContainerException: org.glassfish.embed.EmbeddedException: You must start the server before calling this API method: EmbeddedDeployer.EmbeddedDeployer Constructor.
at com.sun.jersey.test.framework.spi.container.embedded.glassfish.EmbeddedGlassFishTestContainerFactory$EmbeddedGlassFishTestContainer.stop(EmbeddedGlassFishTestContainerFactory.java:154)
at com.sun.jersey.test.framework.JerseyTest.tearDown(JerseyTest.java:312)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
When I remove setUp()
method from the class everything works fine. What's wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在设置中尝试
super.setUp();
。当您删除它时,它将调用其继承版本的
super
。这很好。但是当您添加自己的设置时,您已经覆盖了
super 的
版本。Try
super.setUp();
in setup.When you remove it it will call its inherited version of
super
. which is fine.But as you add your own setUp you have overridden the
super's
version .您无意中覆盖了它的
setUp()
方法。尝试将其名称更改为其他名称,为什么不说出来,before()
。原始的
setUp()
方法通过调用TestContainer.start()
来调用测试容器。在您的情况下,它无法执行此操作,因为您重写了该方法并且从未对super.setUp()
进行任何调用。因此,它抱怨,你必须启动服务器......某某
。You are unintentionally overriding its
setUp()
method. Try changing its name to something else, why not say it,before()
.The original
setUp()
method invokes test container by callingTestContainer.start()
. In your case it couldn't do that, because you overrided the method and never made any call tosuper.setUp()
. Therefore, its complaining that,You must start the server.... so and so
.