스프링 부트를 사용하여 응용 프로그램을 만들고 Solr에 쿼리하고 문서를 추가하려고합니다. 그래서 저는 Spring 데이터 solr을 사용합니다. 의존 관계는 다음과 같습니다.커스텀 스프링 데이터 솔라 저장소를 구현할 때 SolrOperations 빈 삽입 방법?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
그런 다음 Solr 저장소 구성을위한 구성 클래스를 만듭니다. 봄 덕분에 모든 것이 간단하고 잘 작동합니다.
@Configuration
@EnableSolrRepositories(basePackages = { "xxx.xx.xx.resource.repository.solr" },multicoreSupport = true)
public class SolrConfiguration {
@Bean
public SolrClient solrClient(@Value("${solr.host}") String solrHost) {
return new HttpSolrClient(solrHost);
}
}
기본 변환기가 중첩 된 Java 객체를 변환 할 수 없으므로 문서 저장을위한 사용자 정의 함수를 추가하고 싶습니다. 나는 저장을 위해 SolrClient
bean 또는 SolrTemplate 빈을 사용할 계획이다.
public class HouseSolrRepositoryImpl extends SimpleSolrRepository<House, String> implements HouseSolrRepository{
@Autowired
private SolrClient solrClient;
@Override
public House save(House house) throw Exception{
// Do converting
solrClient.save(doc);
solrClient.commit();
return house;/
}
}
그러나 autowire가 SolrClient
의 경로는 문서 객체 (@Document(solrCoreName = "gettingstarted")
)에서 경로에 solrCoreName
을하지 않습니다. 그냥 http://localhost:8983/solr
으로 요청하지만 핵심 이름은 http://localhost:8983/solr/gettingstarted
이 아닙니다.
초기화 리포지토리 빈 중에는 solrCoreName
이 설정되어 있으므로 내 구성에 포함되지 않습니다.
한편 SimpleSolrRepository
의 SolrOperation
콩도 null이되며 findOne()
과 같은 다른 쿼리는 제대로 작동하지 않습니다.
효과가 있습니까? 제 경우에는 메소드를 호출 할 때마다 새로운 인스턴스를 생성합니다. – Maralc