In reference to this article
I want to manually set up a repository using my own SolrTemplate
. This is because I have multiple instances of Solr running and I want a repo for each one of them. Here's what I do:
Bean definition:
<bean id="currencySolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.server.currency.url}" index="0"/>
</bean>
<bean id="currencySolrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg index="0" ref="currencySolrServer"/>
</bean>
I have a very basic repository:
@Component
public interface CurrencyRepository extends SolrCrudRepository<SolrInputDocument, String>
{
}
A service class:
@Service
public class SolrService
{
@Resource
@Qualifier("currencySolrTemplate")
SolrTemplate currencySolrTemplate;
private CurrencyRepository repository;
/*init the repo*/
@PostConstruct
public void init()
{
log.debug("Creating SolrRepository");
repository = new SolrRepositoryFactory(currencySolrTemplate)
.getRepository(CurrencyRepository.class);
log.debug( "SolrRepositiory created" );
}
}
According to the referenced article, Bob's my uncle, But, instead it blows up in the init()
method with:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CurrencyRepository': Cannot resolve reference to bean 'solrTemplate' while setting bean property 'solrOperations'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'solrTemplate' is defined
Right. Convention over configuration. Why is CurrencyRepository
still looking for a reference to a default SolrTemplate
although I have given it my own currencySolrTemplate
?