gpt4 book ai didi

java - 运行 jerseyTest 时出现 filenotfoundException - 缺少 applicationContext.xml

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:49 25 4
gpt4 key购买 nike

我正在 Hello World 上运行测试,试图在我的 spring java 程序中遵循 Jersey 框架。

我已经扩展了 JerseyTest,但出现了上述错误。示例 Jersey 给出 link似乎没有帮助。

public class SimpleTest extends JerseyTest {



@Override
protected Application configure() {
return new ResourceConfig(RestService.class);
}

@Test
public void test() {
final String hello = target("\service\hello").request().get(HelloModel.class);
assertEquals("Hello World!", hello);
}
}

最佳答案

在 Jersey 2.26 中,依赖项已更改为 jersey-spring4,但如果您不想想要启动整个 Spring 上下文,则需要稍微刷新一下答案。

创建对象:

    final ResourceConfig resourceConfig = new ResourceConfig(restResource);

就我而言,我只需要一个空上下文:

    final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
resourceConfig.property("contextConfig", context);

这使得 JerseyTest 能够成功运行。

关于java - 运行 jerseyTest 时出现 filenotfoundException - 缺少 applicationContext.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45591523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com