未找到org.apache.solr.client.solrj.embedded.EmbeddedSolrServer的类文件

时间:2013-12-02 20:39:02

标签: spring solr spring-data spring-data-solr

我想在我现有的Web应用程序中设置一个嵌入式Solr服务器。但我已经没有创建豆子了:

[ERROR] /home/danny/workspace/example/src/main/java/com/example/config/MainConfig.java:[76,45] cannot access org.apache.solr.client.solrj.embedded.EmbeddedSolrServer
  class file for org.apache.solr.client.solrj.embedded.EmbeddedSolrServer not found

这是我的maven依赖(我想使用注释部分here中提到的嵌入式服务器版本):

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-solr</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

这是我的Configuration类(它的必要部分):

@Configuration
@ComponentScan(basePackages = "com.example", excludeFilters = { @ComponentScan.Filter(Configuration.class) })
@EnableSolrRepositories
public class MainConfig {
    @Bean
    public SolrServer solrServer() {
        EmbeddedSolrServerFactory factory = new EmbeddedSolrServerFactory("classpath:com/example/solr");
        return factory.getSolrServer(); // Eclipse tells: The type org.apache.solr.client.solrj.embedded.EmbeddedSolrServer cannot be resolved. It is indirectly referenced from required .class files
    }

    @Bean
    public SolrOperations solrTemplate() {
        return new SolrTemplate(solrServer());
    }
}

1 个答案:

答案 0 :(得分:3)

你缺少solr依赖本身

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-core</artifactId>
    <version>THE_VERSION_YOU_WANT_TO_USE</version>
</dependency>