gpt4 book ai didi

jersey - Dropwizard/Jersey - 运行测试时缺少公共(public)方法的依赖项

转载 作者:行者123 更新时间:2023-12-04 15:24:36 25 4
gpt4 key购买 nike

我在使用 Dropwizard: 0.6.1 (jersey 1.15) 运行 resourceTest 时遇到了“缺少依赖项”异常,有人在这种情况下有经验吗?

我的测试文件 :

public class MyResourceImplTest extends ResourceTest {
........
@Override
protected void setUpResources() throws Exception {
addResource(new MyResourceImpl(new myConfiguration()));
}
}

异常(exception) :
Dec 13, 2012 2:10:41 PM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer <init>
INFO: Creating low level InMemory test container configured at the base URI http://localhost:9998/
Dec 13, 2012 2:10:42 PM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer start
INFO: Starting low level InMemory test container
Dec 13, 2012 2:10:42 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.15 10/30/2012 02:40 PM'
Dec 13, 2012 2:10:42 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public javax.ws.rs.core.StreamingOutput com.****************.********(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String) at parameter at index 0
Dec 13, 2012 2:10:42 PM com.sun.jersey.test.framework.spi.container.inmemory.InMemoryTestContainerFactory$InMemoryTestContainer stop
INFO: Stopping low level InMemory test container

最佳答案

看起来 Jersey 无法注入(inject) HttpServletRequest

您的端点之一是这样配置的吗?

public StreamingOutput something(@Context HttpServletRequest request, String a, String b) {}

如果是这样,您可能需要重新考虑您的设计,并选择
@Context
private HttpContext context;

public StreamingOutput something(String a, String b) {

System.out.println("Request info "+context.getRequest().getAbsolutePath());

}

这可能会产生更清洁的方法。只要您依赖 Class资源注册,然后您可以保证每个请求都有一个新实例,这应该避免线程问题。

关于jersey - Dropwizard/Jersey - 运行测试时缺少公共(public)方法的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13861897/

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