注入点和不可代理依赖的问题

bhmjp9jg  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(371)

有人能解释一下为什么我的班级是这样定义的吗

public abstract class GenericClient
{
  private static final Logger LOG = LoggerFactory.getLogger(GenericClient.class);

  @Inject
  @ConfigProperty( name = "dirx-ws.url" )
  private String              url;

  private final Client        client;

  private HttpHeaders         httpHeaders;

  public GenericClient()
  {
    this.client = ClientBuilder.newClient();
  }

  public void setHttpHeaders( final HttpHeaders httpHeaders )
  {
    this.httpHeaders = httpHeaders;
  }

  protected HttpHeaders getHttpHeaders()
  {
    return this.httpHeaders;
  }

  protected Client getClient()
  {
    return this.client;
  }

  protected MultivaluedMap<String, Object> getHeaders()
  {
    final MultivaluedMap<String, String> myHttpHeaders = this.httpHeaders.getRequestHeaders();

    final MultivaluedMap<String, Object> result = new MultivaluedHashMap<String, Object>();

    myHttpHeaders.forEach(( name, values ) -> {
      result.putSingle(name, values.size() != 1 ? values : values.get(0));
    });

    printHeaderInfo();

    return result;
  }

  protected UriBuilder createURIBuilder( final String... paths )
  {
    final UriBuilder uriBuilder = UriBuilder.fromUri(this.url);

    for (final String path : paths)
    {
      uriBuilder.path(path);
    }

    return uriBuilder;
  }
}

没有错误,但是如果我这样定义它(唯一的变化是私有的uribuilder createduri;以及更新的方法createuribuilder)

public abstract class GenericClient
{
  private static final Logger LOG = LoggerFactory.getLogger(GenericClient.class);

  @Inject
  @ConfigProperty( name = "dirx-ws.url" )
  private String              url;

  private final Client        client;

  private HttpHeaders         httpHeaders;

  private UriBuilder          createdURI;

  public GenericClient()
  {
    this.client = ClientBuilder.newClient();
  }

  public void setHttpHeaders( final HttpHeaders httpHeaders )
  {
    this.httpHeaders = httpHeaders;
  }

  protected HttpHeaders getHttpHeaders()
  {
    return this.httpHeaders;
  }

  protected Client getClient()
  {
    return this.client;
  }

  protected MultivaluedMap<String, Object> getHeaders()
  {
    final MultivaluedMap<String, String> myHttpHeaders = this.httpHeaders.getRequestHeaders();

    final MultivaluedMap<String, Object> result = new MultivaluedHashMap<String, Object>();

    myHttpHeaders.forEach(( name, values ) -> {
      result.putSingle(name, values.size() != 1 ? values : values.get(0));
    });

    printHeaderInfo();

    return result;
  }

  protected final UriBuilder createURIBuilder( final String... paths )
  {
    if (this.createdURI == null)
    {
      this.createdURI = UriBuilder.fromUri(this.url);

      for (final String path : paths)
      {
        this.createdURI.path(path);
      }
    }

    return this.createdURI;
  }
}

我得到了错误
weld-001410:注入点具有不可代理的依赖项:[backedannotatedfield]@inject private ch.ethz.id.sws.iamws.webservices.endpoint.requestinterceptor.userclient[信息]位于ch.ethz.id.sws.iamws.webservices.endpoint.requestinterceptor.userclient(requestinterceptor)。java:0)
我的requestscoped userclient类(仅)有一个空的公共构造函数,它扩展了genericclient。

des4xlb0

des4xlb01#

问题解决了。从createuribuilder方法中删除final完成了此任务。
如果有人能向我解释为什么将方法设置为“final”是个问题,我会很高兴。

相关问题