我希望使用我自己的SolrTemplate手动设置一个存储库。这是因为我有多个Solr实例正在运行,我希望每个实例都有一个回购。我要做的是:
Bean定义:
<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>我有一个非常基本的存储库:
@Component
public interface CurrencyRepository extends SolrCrudRepository<SolrInputDocument, String>
{
}服务舱:
@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" );
}
}根据引用的文章,Bob是我的叔叔,但是,相反,它在init()方法中爆炸了:
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正确的。约定高于配置。为什么CurrencyRepository仍然在寻找默认SolrTemplate的引用,尽管我已经给了它自己的currencySolrTemplate
发布于 2014-03-26 23:41:41
找到了!我的上下文文件中有一个老行:
<solr:repositories base-package="com.sundberg.solr.repository"/>这在某种程度上导致回购寻找默认的solrTemplate。删除这条线解决了问题。请随意分享一些关于这一点的光明。总的来说,Spring的Solr框架的文档并不是很全面。
https://stackoverflow.com/questions/22675266
复制相似问题