カスタムリポジトリ機能を備えたSpringデータSolr 1.4を使用して、この記事に従ってカウント関数を実装しようとしています:リンク
複数のコアを使用するように構成された Solr を使用しています。通常のリポジトリ インターフェースは正しいSolrTemplate
とSolrServer
インスタンスを取得して使用しますが、カスタム リポジトリはテンプレートの同じインスタンスを取得しません。を使用し@Resource
て Bean を注入するだけでなく、Spring アプリケーション コンテキストを取得して、そこから Bean をプルしようとしました。どちらの場合もsolrServer
、自分のコアが何であるかを知らない Bean 参照を取得しているため、http://localhost:8983/solrではなくhttp://localhost:8983/solrで solr に到達しようとすると、クエリは失敗します。 /myCore
Bean の定義は次のようになります。
@Bean
@Scope(value=ConfigurableBeanFactory.SCOPE_SINGLETON)
public SolrServer solrServer() {
SolrServer server = new HttpSolrServer(solrServerUrl);
return server;
}
@Bean(name = "solrTemplate")
@Scope(value=ConfigurableBeanFactory.SCOPE_SINGLETON)
public SolrTemplate solrTemplate(SolrServer server) throws Exception {
SolrTemplate template = new SolrTemplate(server);
template.setSolrCore(mainCore);
return template;
}
そして、私のテストは次のようになります。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SearchEngineApplication.class, loader=SpringApplicationContextLoader.class)
public class MainRepositoryTest {
@Autowired
private MainRepository mainRepository;
...
@Test
public void testCountResults(){
long count= citcMainRepository.count("red");
System.out.println("Found " + count + " results for the term red" );
assertTrue(count > 0);
}
}
テストは常に失敗します。
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/select
到達するはずの適切なURLが/solr/select/myCore
ここで設定を誤った可能性があることについて何か提案はありますか? 任意/すべての返信を歓迎します!
-- グリフ