Glassfish Embedded 容器有什么问题?

发布于 2024-09-27 09:49:18 字数 1450 浏览 1 评论 0原文

这是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

战皆罪 2024-10-04 09:49:18

在设置中尝试 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 .

凯凯我们等你回来 2024-10-04 09:49:18

您无意中覆盖了它的 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 calling TestContainer.start(). In your case it couldn't do that, because you overrided the method and never made any call to super.setUp(). Therefore, its complaining that, You must start the server.... so and so.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文