Question

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?

Was it helpful?

Solution

Found it! I had a old line in my context file:

<solr:repositories base-package="com.sundberg.solr.repository"/>

This, somehow, caused the repo to look for a default solrTemplate. Removing this line solved the problem. Feel free to share some light on this. Overall, the docs of Spring's Solr framework are not very comprehensive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top