欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Solr 7.5 Expected mime type application/json but got text/plain.

程序员文章站 2022-04-03 16:03:46
...
SolrJ版本7.5,Solr版本7.5。查询测试代码如下:
        SolrClient solr = new HttpSolrClient.Builder(solrUrl).build();

        SolrQuery query=new SolrQuery();
        query.set("q","title:"+queryStr);
        query.set("wt","json");
        try {
            QueryResponse solrResponse=solr.query(query );
            SolrDocumentList results = solrResponse.getResults();
            System.out.println(results.toString());
        } catch (SolrServerException e) {
            e.printStackTrace();
        }


执行抛出异常信息:
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://127.0.0.1:8983/solr/xxxxxx: Expected mime type application/json but got text/plain

经过一番苦苦搜索,原因居然出在 solr-7.5.0/server/solr/${core}/conf/solrconfig.xml
该配置文件中有如下配置:
<queryResponseWriter name="json" class="solr.JSONResponseWriter">
    <!-- For the purposes of the tutorial, JSON responses are written as
     plain text so that they are easy to read in *any* browser.
     If you expect a MIME type of "application/json" just remove this override.
    -->
    <str name="content-type">text/plain; charset=UTF-8</str>
</queryResponseWriter>

各位请注意看注释里面的那段话!!!
将text/plain 修改为 application/json 运行一切正常。
相关标签: solr java