我想在我现有的 Web 应用程序中设置一个嵌入式 Solr 服务器。但我在创建 bean 方面已经失败了:
[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 依赖项(我想使用此处注释部分中提到的嵌入式服务器版本):
<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
@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());
}
}