加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Dropwizard / Jersey – 运行测试时缺少公共方法的依赖项

发布时间:2020-12-13 20:47:28 所属栏目:百科 来源:网络整理
导读:我在使用Dropwizard运行resourceTest时遇到了“Missing dependency”异常:0.6.1(jersey 1.15),有没有人有这种情况的经验? 我的测试文件: public class MyResourceImplTest extends ResourceTest { ........ @Override protected void setUpResources() th
我在使用Dropwizard运行resourceTest时遇到了“Missing dependency”异常:0.6.1(jersey 1.15),有没有人有这种情况的经验?

我的测试文件:

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

例外:

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无法注入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资源注册,就可以保证每个请求都有一个新实例,这样可以避免线程问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读