从上下文获取空

时间:2019-04-11 16:39:47

标签: java servlet-filters dropwizard

为什么我在此将resourceInfo设置为null。还有其他获取资源类和资源方法的方法吗?

@Provider
@Authenticate
@Transactional
public class TestFilter2 implements ContainerRequestFilter {

  private final SessionRepository sessionRepository;

  @Context
  public ResourceInfo resourceInfo;

  @Inject
  public TestFilter2(SessionRepository sessionRepository) {
    this.sessionRepository = sessionRepository;
  }

  @Override
  public void filter(ContainerRequestContext requestContext) throws IOException {
    check();
  }


  private void check() {
    sessionRepository.getActiveSessionBySessionId("dsfsdf");

  }
}

1 个答案:

答案 0 :(得分:-1)

@context批注不允许您注入ResourceInfo类型,here是您可以使用@context注入的类型:

  
      
  • SecurityContext
  •   
  • 请求
  •   
  • ResourceContext
  •   
  • ServletConfig
  •   
  • ServletContext
  •   
  • HttpServletRequest
  •   
  • HttpServletResponse
  •   
  • HttpHeaders
  •   
  • UriInfo
  •