Java Spring - 缺少类型SolrClient,MulticoreSolrServerFactory

时间:2016-05-20 11:53:00

标签: java spring maven solr

我正在尝试将Solr实现到我的Java Spring应用程序中,但是由于STS无法找到SolrClient和MultiCoreSolrServerFactory,因此我遇到了依赖性问题。这是让我烦恼的课程:

package lt.gerasolutions.gsm.core.classifiers.domain;

import javax.annotation.Resource;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.repository.SolrCrudRepository;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;
import org.springframework.data.solr.server.support.HttpSolrClientFactoryBean;

@Configuration
@EnableSolrRepositories(basePackages={"lt.gerasolutions.gsm.core.solrRepositories"}, 
multicoreSupport=true)
public class SolrContext {

  static final String SOLR_HOST = "solr.host";

  @Resource 
  private Environment environment;

  @Bean
  public SolrServer solrServer() {
    String solrHost = environment.getRequiredProperty(SOLR_HOST);
    SolrServer server = new HttpSolrServer(solrHost);
    MulticoreSolrServerFactory factory;
    //I was told to use this factory to return a server, but eclipse cannot find it unfortunately.
  }

  @Bean (name = "EN")
  public SolrTemplate solrEn(){
      return new SolrTemplate(solrServer());
      //The type org.apache.solr.client.solrj.SolrClient cannot be resolved. It is indirectly referenced from required .class files
  }

  @Bean (name = "LT")
  public SolrTemplate solrLt(){
      return new SolrTemplate(solrServer());
  }

}

我的依赖项由maven管理,这是它的pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>a</name>
    <description></description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <scope>runtime</scope>
            </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>
                spring-boot-starter-data-elasticsearch
            </artifactId>
        </dependency>

        <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-solr</artifactId>
                <version>2.0.1.RELEASE</version>
            </dependency>

        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-core</artifactId>
            <version>6.0.0</version>
            <exclusions>
                <exclusion>
                            <artifactId>jdk.tools</artifactId>
                            <groupId>jdk.tools</groupId>
                     </exclusion>
                </exclusions>
        </dependency>

        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-solr</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

1 个答案:

答案 0 :(得分:1)

检查依赖项中的solrj jar版本。 由于Spring引导具有4.10.4的依赖性,因此新版本不会被覆盖。旧版本没有Cloud类。

您可以手动添加

{{1}}

然后你会有新版本。