使用基本身份验证在 Spring 中配置 HttpClient

发布于 2024-09-25 20:32:05 字数 482 浏览 2 评论 0原文

我正在我们的应用程序中实现 SOLR 服务器。 我们使用 SolrJ 包中的 CommonsHttpSolrServer 连接到使用 commons-httpclient 的 solr 服务器。 我们也使用Spring。

现在我们的系统管理员保护了 solr 服务器(有充分的理由)并使用基本身份验证。

如何实例化具有基本身份验证的 HttpClient 以注入到 SolrJ 中?

例如

<bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.CommonsHttpSolrServer">
    <constructor-arg value="${solrserver_path}" />
    <constructor-arg ref="solrHttpClient" />
</bean>

谢谢!

I'm implementing a SOLR server in our application.
We use the CommonsHttpSolrServer in the SolrJ package to connect to our solr server which uses the commons-httpclient.
We also use Spring.

Now our sysadmin secured the solr server (with good reason) and used Basic Auth.

How can I instantiate a HttpClient with Basic Auth to be injected in the SolrJ?

e.g.

<bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.CommonsHttpSolrServer">
    <constructor-arg value="${solrserver_path}" />
    <constructor-arg ref="solrHttpClient" />
</bean>

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-10-02 20:32:05

不幸的是,您必须使用创建客户端的工厂。参与身份验证的类中没有凭证的 bean 属性,即
HttpState.setCredentials(AuthScope, Credentials) 这不是一个 bean 属性。

我将 HttpClientFactory 上传到 github。还可以查看 spring 上下文的片段

Unfortunately, you have to use a factory that creates the client. There is no bean property for credentials in the classes involved in authentication, namely
HttpState.setCredentials(AuthScope, Credentials) which isn't a bean property.

I uploaded my HttpClientFactory to github. Se also the snippet for the spring context.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文