2

Hi , I am into Spring Data Solr with Spring boot for configuration orchestration .

<!-- begin snippet: js hide: false console: true babel: false -->
`

import java.util.List;

import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.solr.core.SolrOperations;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.repository.support.SimpleSolrRepository;
import org.springframework.stereotype.Repository;

import com.db.Customer360DegreeMetaService.model.SolrCustomer;


public class SolrCustomerModelDaoImpl extends SimpleSolrRepository<SolrCustomer, String> implements SolrCustomerModelDao {
    
//  public static void main(String[] args) {
//      // TODO Auto-generated method stub
//
//  }

    public SolrCustomerModelDaoImpl(SolrOperations solrOperations, Class<SolrCustomer> entityClass) {
        super(solrOperations, entityClass);
        // TODO Auto-generated constructor stub
    }

    @Override
    public List<SolrCustomer> getDetails() {
        // TODO Auto-generated method stub
        return (List<SolrCustomer>) this.findAll();     
    }

    @Override
    public List<SolrCustomer> findByCustomQuery(String searchTerm) {
        // TODO Auto-generated method stub
        return this.findByCustomQuery(searchTerm);
    }

}
 
`
When I try to Post my SolrDocument Data to my Service Class which has been injected with above Solr

    
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.transaction.Transactional;

import org.hibernate.annotations.Proxy;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;
import org.springframework.stereotype.Repository;

import com.db.Customer360DegreeMetaService.model.SolrCustomer;

@NoRepositoryBean
public interface SolrCustomerModelDao extends SolrCrudRepository<SolrCustomer, String> {

    @Query(value = "*:*")
    List<SolrCustomer> getDetails(); 

    @Query("sysId:*?0* OR firstName:*?0* OR lastName:*?0* OR mobileNo:*?0* OR email:*?0*")
    public List<SolrCustomer> findByCustomQuery(String searchTerm);

    String columns[] = {"sysId","anId","custCode","name","firstName","lasName","gender",
            "consCustCode","pincode","customerType","mailId","createdUserId","createdDate"
            ,"updatedUserId", "updatedDate" };
}

And I do have an NoRepositryBean ,which is above one  , and an implementation of the Repository :

    
import java.util.List;

import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.solr.core.SolrOperations;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.repository.support.SimpleSolrRepository;
import org.springframework.stereotype.Repository;

import com.db.Customer360DegreeMetaService.model.SolrCustomer;


public class SolrCustomerModelDaoImpl extends SimpleSolrRepository<SolrCustomer, String> implements SolrCustomerModelDao {
    
//  public static void main(String[] args) {
//      // TODO Auto-generated method stub
//
//  }

    public SolrCustomerModelDaoImpl(SolrOperations solrOperations, Class<SolrCustomer> entityClass) {
        super(solrOperations, entityClass);
        // TODO Auto-generated constructor stub
    }

    @Override
    public List<SolrCustomer> getDetails() {
        // TODO Auto-generated method stub
        return (List<SolrCustomer>) this.findAll();     
    }

    @Override
    public List<SolrCustomer> findByCustomQuery(String searchTerm) {
        // TODO Auto-generated method stub
        return this.findByCustomQuery(searchTerm);
    }
 I am getting Below exception when trying to Post Solr Documents ;

    @SolrDocument(solrCoreName="ganaprimer")
@JsonRootName(value="customer")
public class SolrCustomer extends JSONObject{
    
    @javax.persistence.Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id 
    private String anId;
    
    @Field
    private String custCode;
    
    @Field
    private String name;
    
    @Field
    private String firstName ;
    @Field
    private String lasName;
    
    @Field
    private Character gender;
    @Field
    private String consCustCode;
    @Field
    private String pincode;
    @Field
    private String customerType;
    @Field
    private String mailId;
    @Field
    private String createdUserId;
    @Field
    private Date createdDate;
    @Field
    private String updatedUserId;
    @Field
    private Date updatedDate;
    
I am getting below exception : 

2020-09-23 15:54:53 - Completed initialization in 10 ms
org.springframework.dao.DataAccessResourceFailureException: Error from server at http://localhost:8983/solr/ganaprimer: Expected mime type application/octet-stream but got text/html. <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/ganaprimer/ganaprimer/update. Reason:
<pre>    Not Found</pre></p>
</body>
</html>
; nested exception is org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/ganaprimer: Expected mime type application/octet-stream but got text/html. <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/ganaprimer/ganaprimer/update. Reason:
<pre>    Not Found</pre></p>
</body>
</html>

    at org.springframework.data.solr.core.SolrExceptionTranslator.translateExceptionIfPossible(SolrExceptionTranslator.java:84)
    at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:169)
    at org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:221)
    at org.springframework.data.solr.repository.support.SimpleSolrRepository.save(SimpleSolrRepository.java:150)

我已经注入了 SolrCoreName 的 Solr 文档,并尝试将 http://localhost:8983/solr/ganaprimer 作为要为 Solr Hit 注入的 Solr 主机变量。但是我得到的嵌套异常是 org.apache.solr.client。 solrj.impl.HttpSolrClient$RemoteSolrException:有人可以帮助..in 破译 SolrException。

4

0 回答 0