java - Injected SolrTemplate Resource not connected to HttpSolrServer -
i using spring data solr 1.4 custom repository feature try implement count function per article: link
i using solr configured use multiple cores. regular repository interface gets , uses correct solrtemplate
, solrserver
instances, custom repository not same instance of template. in addition using @resource
inject bean, have tried getting spring application context , pulling bean it. in both cases getting solrserver
bean reference not know core is, query fails when tries reach solr at: http://localhost:8983/solr instead of http://localhost:8983/solr/mycore
the bean definition looks this:
@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; }
and test looks this:
@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 term red" ); asserttrue(count > 0); } }
the test fails:
<body><h2>http error 404</h2> <p>problem accessing /solr/select
when proper url should reaching /solr/select/mycore
any suggestions might have misconfigured here? any/all replies appreciated!
-- griff
i able solve problem myself creating second bean of same type , adding qualifier it.
in solrcontext defined bean factory , bean definition such: @bean public solrserverfactory solrserverfactory() { return new multicoresolrserverfactory(new httpsolrserver(solrserverurl)); }
// solrtemplate /solrserverurl/maincore @bean(name = "maintemplate") public solrtemplate maintemplate() throws exception { solrtemplate solrtemplate = new solrtemplate(solrserverfactory()); solrtemplate.setsolrcore(maincore); return solrtemplate; } @bean(name="mainrepo") public mainrepository mainrepository() throws exception { return new solrrepositoryfactory(maintemplate()) .getrepository(citcmainrepository.class, new mainrepositoryimpl(maintemplate())); }
then qualifying repository in unittest such:
public class citcmainrepositorytest {
@autowired @qualifier(value="mainrepo") private mainrepository mainrepository; @test public void testfindbylastname() { list<searchresponse> searchitems= mainrepository.findbylastname("hunt"); asserttrue(searchitems.size() > 0); } ...
}
hope helps else.
-- griff
Comments
Post a Comment