簡體   English   中英

使用solrj連接到具有憑據的solr服務器

[英]Connect to a solr server with credential with solrj

我正在嘗試使用以下代碼連接到Solr服務器:

SolrServer solr = new HttpSolrServer("http://localhost:8080/solr-all");
SolrQuery query = new SolrQuery();

query.setQuery("*:*");
query.setRows(10);
query.setStart(0);

QueryResponse response = solr.query(query);
System.out.println(response);

但我得到這個錯誤:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Server at http://localhost:8080/solr-all returned non ok status:401, message:Unauthorized

我真的不知道如何設置用戶名和密碼,我在網上使用htttpclient找到了許多實例,但沒有一個對我htttpclient

設置憑據:

httpclient.getCredentialsProvider().setCredentials(
                    AuthScope.ANY,
                    new UsernamePasswordCredentials(username, password));
solrServer = new HttpSolrServer(solrUrl, httpclient);//with credentials

檢查類似的討論:

具有基本身份驗證的Solr 4

您能否檢查Slf4j在運行時是否可用?

 Failed to load class "org.slf4j.impl.StaticLoggerBinder"

意味着您的代碼在運行時需要此類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM